home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Compilers⁄Interps / GCC-2.3.3r12 / Sources / genattrtab.c < prev    next >
Encoding:
Text File  |  1993-04-26  |  152.6 KB  |  5,664 lines  |  [TEXT/MPS ]

  1. /* Generate code from machine description to compute values of attributes.
  2.    Copyright (C) 1991 Free Software Foundation, Inc.
  3.    Contributed by Richard Kenner (kenner@nyu.edu)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. /* This program handles insn attributes and the DEFINE_DELAY and
  22.    DEFINE_FUNCTION_UNIT definitions.
  23.  
  24.    It produces a series of functions named `get_attr_...', one for each insn
  25.    attribute.  Each of these is given the rtx for an insn and returns a member
  26.    of the enum for the attribute.
  27.  
  28.    These subroutines have the form of a `switch' on the INSN_CODE (via
  29.    `recog_memoized').  Each case either returns a constant attribute value
  30.    or a value that depends on tests on other attributes, the form of
  31.    operands, or some random C expression (encoded with a SYMBOL_REF
  32.    expression).
  33.  
  34.    If the attribute `alternative', or a random C expression is present,
  35.    `constrain_operands' is called.  If either of these cases of a reference to
  36.    an operand is found, `insn_extract' is called.
  37.  
  38.    The special attribute `length' is also recognized.  For this operand, 
  39.    expressions involving the address of an operand or the current insn,
  40.    (address (pc)), are valid.  In this case, an initial pass is made to
  41.    set all lengths that do not depend on address.  Those that do are set to
  42.    the maximum length.  Then each insn that depends on an address is checked
  43.    and possibly has its length changed.  The process repeats until no further
  44.    changed are made.  The resulting lengths are saved for use by
  45.    `get_attr_length'.
  46.  
  47.    A special form of DEFINE_ATTR, where the expression for default value is a
  48.    CONST expression, indicates an attribute that is constant for a given run
  49.    of the compiler.  The subroutine generated for these attributes has no
  50.    parameters as it does not depend on any particular insn.  Constant
  51.    attributes are typically used to specify which variety of processor is
  52.    used.
  53.    
  54.    Internal attributes are defined to handle DEFINE_DELAY and
  55.    DEFINE_FUNCTION_UNIT.  Special routines are output for these cases.
  56.  
  57.    This program works by keeping a list of possible values for each attribute.
  58.    These include the basic attribute choices, default values for attribute, and
  59.    all derived quantities.
  60.  
  61.    As the description file is read, the definition for each insn is saved in a
  62.    `struct insn_def'.   When the file reading is complete, a `struct insn_ent'
  63.    is created for each insn and chained to the corresponding attribute value,
  64.    either that specified, or the default.
  65.  
  66.    An optimization phase is then run.  This simplifies expressions for each
  67.    insn.  EQ_ATTR tests are resolved, whenever possible, to a test that
  68.    indicates when the attribute has the specified value for the insn.  This
  69.    avoids recursive calls during compilation.
  70.  
  71.    The strategy used when processing DEFINE_DELAY and DEFINE_FUNCTION_UNIT
  72.    definitions is to create arbitrarily complex expressions and have the
  73.    optimization simplify them.
  74.  
  75.    Once optimization is complete, any required routines and definitions
  76.    will be written.
  77.  
  78.    An optimization that is not yet implemented is to hoist the constant
  79.    expressions entirely out of the routines and definitions that are written.
  80.    A way to do this is to iterate over all possible combinations of values
  81.    for constant attributes and generate a set of functions for that given
  82.    combination.  An initialization function would be written that evaluates
  83.    the attributes and installs the corresponding set of routines and
  84.    definitions (each would be accessed through a pointer).
  85.  
  86.    We use the flags in an RTX as follows:
  87.    `unchanging' (RTX_UNCHANGING_P): This rtx is fully simplified
  88.       independent of the insn code.
  89.    `in_struct' (MEM_IN_STRUCT_P): This rtx is fully simplified
  90.       for the insn code currently being processed (see optimize_attrs).
  91.    `integrated' (RTX_INTEGRATED_P): This rtx is permanent and unique
  92.       (see attr_rtx).
  93.    `volatil' (MEM_VOLATILE_P): During simplify_by_exploding the value of an
  94.       EQ_ATTR rtx is true if !volatil and false if volatil.  */
  95.  
  96.  
  97. #include "hconfig.h"
  98. #include "rtl.h"
  99. #include "insn-config.h"    /* For REGISTER_CONSTRAINTS */
  100. #include <stdio.h>
  101. #include "gvarargs.h"
  102.  
  103. #ifndef VMS
  104. #ifndef USG
  105. #ifndef MPW
  106. #include <sys/time.h>
  107. #include <sys/resource.h>
  108. #endif
  109. #endif
  110. #endif
  111.  
  112. /* We must include obstack.h after <sys/time.h>, to avoid lossage with
  113.    /usr/include/sys/stdtypes.h on Sun OS 4.x.  */
  114. #include "obstack.h"
  115.  
  116. static struct obstack obstack, obstack1, obstack2;
  117. struct obstack *rtl_obstack = &obstack;
  118. struct obstack *hash_obstack = &obstack1;
  119. struct obstack *temp_obstack = &obstack2;
  120.  
  121. #define obstack_chunk_alloc xmalloc
  122. #define obstack_chunk_free free
  123.  
  124. /* Define this so we can link with print-rtl.o to get debug_rtx function.  */
  125. char **insn_name_ptr = 0;
  126.  
  127. extern void free ();
  128. extern rtx read_rtx ();
  129.  
  130. static void fatal ();
  131. void fancy_abort ();
  132.  
  133. /* enough space to reserve for printing out ints */
  134. #define MAX_DIGITS (HOST_BITS_PER_INT * 3 / 10 + 3)
  135.  
  136. /* Define structures used to record attributes and values.  */
  137.  
  138. /* As each DEFINE_INSN, DEFINE_PEEPHOLE, or DEFINE_ASM_ATTRIBUTES is
  139.    encountered, we store all the relevant information into a
  140.    `struct insn_def'.  This is done to allow attribute definitions to occur
  141.    anywhere in the file.  */
  142.  
  143. struct insn_def
  144. {
  145.   int insn_code;        /* Instruction number. */
  146.   int insn_index;        /* Expression numer in file, for errors. */
  147.   struct insn_def *next;    /* Next insn in chain. */
  148.   rtx def;            /* The DEFINE_... */
  149.   int num_alternatives;        /* Number of alternatives.  */
  150.   int vec_idx;            /* Index of attribute vector in `def'. */
  151. };
  152.  
  153. /* Once everything has been read in, we store in each attribute value a list
  154.    of insn codes that have that value.  Here is the structure used for the
  155.    list.  */
  156.  
  157. struct insn_ent
  158. {
  159.   int insn_code;        /* Instruction number.  */
  160.   int insn_index;        /* Index of definition in file */
  161.   struct insn_ent *next;    /* Next in chain.  */
  162. };
  163.  
  164. /* Each value of an attribute (either constant or computed) is assigned a
  165.    structure which is used as the listhead of the insns that have that
  166.    value.  */
  167.  
  168. struct attr_value
  169. {
  170.   rtx value;            /* Value of attribute.  */
  171.   struct attr_value *next;    /* Next attribute value in chain.  */
  172.   struct insn_ent *first_insn;    /* First insn with this value.  */
  173.   int num_insns;        /* Number of insns with this value.  */
  174.   int has_asm_insn;        /* True if this value used for `asm' insns */
  175. };
  176.  
  177. /* Structure for each attribute.  */
  178.  
  179. struct attr_desc
  180. {
  181.   char *name;            /* Name of attribute. */
  182.   struct attr_desc *next;    /* Next attribute. */
  183.   int is_numeric;        /* Values of this attribute are numeric. */
  184.   int negative_ok;        /* Allow negative numeric values.  */
  185.   int unsigned_p;        /* Make the output function unsigned int.  */
  186.   int is_const;            /* Attribute value constant for each run.  */
  187.   int is_special;        /* Don't call `write_attr_set'. */
  188.   struct attr_value *first_value; /* First value of this attribute. */
  189.   struct attr_value *default_val; /* Default value for this attribute. */
  190. };
  191.  
  192. #define NULL_ATTR (struct attr_desc *) NULL
  193.  
  194. /* A range of values.  */
  195.  
  196. struct range
  197. {
  198.   int min;
  199.   int max;
  200. };
  201.  
  202. /* Structure for each DEFINE_DELAY.  */
  203.  
  204. struct delay_desc
  205. {
  206.   rtx def;            /* DEFINE_DELAY expression.  */
  207.   struct delay_desc *next;    /* Next DEFINE_DELAY. */
  208.   int num;            /* Number of DEFINE_DELAY, starting at 1.  */
  209. };
  210.  
  211. /* Record information about each DEFINE_FUNCTION_UNIT.  */
  212.  
  213. struct function_unit_op
  214. {
  215.   rtx condexp;            /* Expression TRUE for applicable insn.  */
  216.   struct function_unit_op *next; /* Next operation for this function unit.  */
  217.   int num;            /* Ordinal for this operation type in unit.  */
  218.   int ready;            /* Cost until data is ready.  */
  219.   int issue_delay;        /* Cost until unit can accept another insn.  */
  220.   rtx conflict_exp;        /* Expression TRUE for insns incurring issue delay.  */
  221.   rtx issue_exp;        /* Expression computing issue delay.  */
  222. };
  223.  
  224. /* Record information about each function unit mentioned in a
  225.    DEFINE_FUNCTION_UNIT.  */
  226.  
  227. struct function_unit
  228. {
  229.   char *name;            /* Function unit name.  */
  230.   struct function_unit *next;    /* Next function unit.  */
  231.   int num;            /* Ordinal of this unit type.  */
  232.   int multiplicity;        /* Number of units of this type.  */
  233.   int simultaneity;        /* Maximum number of simultaneous insns
  234.                    on this function unit or 0 if unlimited.  */
  235.   rtx condexp;            /* Expression TRUE for insn needing unit. */
  236.   int num_opclasses;        /* Number of different operation types.  */
  237.   struct function_unit_op *ops;    /* Pointer to first operation type.  */
  238.   int needs_conflict_function;    /* Nonzero if a conflict function required.  */
  239.   int needs_blockage_function;    /* Nonzero if a blockage function required.  */
  240.   int needs_range_function;    /* Nonzero if a blockage range function required.  */
  241.   rtx default_cost;        /* Conflict cost, if constant.  */
  242.   struct range issue_delay;    /* Range of issue delay values.  */
  243.   int max_blockage;        /* Maximum time an insn blocks the unit.  */
  244. };
  245.  
  246. /* Listheads of above structures.  */
  247.  
  248. /* This one is indexed by the first character of the attribute name.  */
  249. #define MAX_ATTRS_INDEX 256
  250. static struct attr_desc *attrs[MAX_ATTRS_INDEX];
  251. static struct insn_def *defs;
  252. static struct delay_desc *delays;
  253. static struct function_unit *units;
  254.  
  255. /* Other variables. */
  256.  
  257. static int insn_code_number;
  258. static int insn_index_number;
  259. static int got_define_asm_attributes;
  260. static int must_extract;
  261. static int must_constrain;
  262. static int address_used;
  263. static int length_used;
  264. static int num_delays;
  265. static int have_annul_true, have_annul_false;
  266. static int num_units;
  267.  
  268. /* Used as operand to `operate_exp':  */
  269.  
  270. enum operator {PLUS_OP, MINUS_OP, POS_MINUS_OP, EQ_OP, OR_OP, MAX_OP, MIN_OP, RANGE_OP};
  271.  
  272. /* Stores, for each insn code, the number of constraint alternatives.  */
  273.  
  274. static int *insn_n_alternatives;
  275.  
  276. /* Stores, for each insn code, a bitmap that has bits on for each possible
  277.    alternative.  */
  278.  
  279. static int *insn_alternatives;
  280.  
  281. /* If nonzero, assume that the `alternative' attr has this value.
  282.    This is the hashed, unique string for the numeral
  283.    whose value is chosen alternative.  */
  284.  
  285. static char *current_alternative_string;
  286.  
  287. /* Used to simplify expressions.  */
  288.  
  289. static rtx true_rtx, false_rtx;
  290.  
  291. /* Used to reduce calls to `strcmp' */
  292.  
  293. static char *alternative_name;
  294.  
  295. /* Simplify an expression.  Only call the routine if there is something to
  296.    simplify.  */
  297. #define SIMPLIFY_TEST_EXP(EXP,INSN_CODE,INSN_INDEX)    \
  298.   (RTX_UNCHANGING_P (EXP) || MEM_IN_STRUCT_P (EXP) ? (EXP)    \
  299.    : simplify_test_exp (EXP, INSN_CODE, INSN_INDEX))
  300.   
  301. /* Simplify (eq_attr ("alternative") ...)
  302.    when we are working with a particular alternative.  */
  303. #define SIMPLIFY_ALTERNATIVE(EXP)                \
  304.   if (current_alternative_string                \
  305.       && GET_CODE ((EXP)) == EQ_ATTR                \
  306.       && XSTR ((EXP), 0) == alternative_name)            \
  307.     (EXP) = (XSTR ((EXP), 1) == current_alternative_string    \
  308.         ? true_rtx : false_rtx);
  309.  
  310. /* These are referenced by rtlanal.c and hence need to be defined somewhere.
  311.    They won't actually be used.  */
  312.  
  313. rtx frame_pointer_rtx, stack_pointer_rtx, arg_pointer_rtx;
  314.  
  315. static rtx attr_rtx ();
  316. static char *attr_printf ();
  317. static char *attr_string ();
  318. static rtx check_attr_test ();
  319. static rtx check_attr_value ();
  320. static rtx convert_set_attr_alternative ();
  321. static rtx convert_set_attr ();
  322. static void check_defs ();
  323. static rtx convert_const_symbol_ref ();
  324. static rtx make_canonical ();
  325. static struct attr_value *get_attr_value ();
  326. static rtx copy_rtx_unchanging ();
  327. static rtx copy_boolean ();
  328. static void expand_delays ();
  329. static rtx operate_exp ();
  330. static void expand_units ();
  331. static rtx simplify_knowing ();
  332. static rtx encode_units_mask ();
  333. static void fill_attr ();
  334. static rtx substitute_address ();
  335. static void make_length_attrs ();
  336. static rtx identity_fn ();
  337. static rtx zero_fn ();
  338. static rtx one_fn ();
  339. static rtx max_fn ();
  340. static rtx simplify_cond ();
  341. static rtx simplify_by_alternatives ();
  342. static rtx simplify_by_exploding ();
  343. static int find_and_mark_used_attributes ();
  344. static void unmark_used_attributes ();
  345. static int add_values_to_cover ();
  346. static int increment_current_value ();
  347. static rtx test_for_current_value ();
  348. static rtx simplify_with_current_value ();
  349. static rtx simplify_with_current_value_aux ();
  350. static void remove_insn_ent ();
  351. static void insert_insn_ent ();
  352. static rtx insert_right_side ();
  353. static rtx make_alternative_compare ();
  354. static int compute_alternative_mask ();
  355. static rtx evaluate_eq_attr ();
  356. static rtx simplify_and_tree ();
  357. static rtx simplify_or_tree ();
  358. static rtx simplify_test_exp ();
  359. static void optimize_attrs ();
  360. static void gen_attr ();
  361. static int count_alternatives ();
  362. static int compares_alternatives_p ();
  363. static int contained_in_p ();
  364. static void gen_insn ();
  365. static void gen_delay ();
  366. static void gen_unit ();
  367. static void write_test_expr ();
  368. static int max_attr_value ();
  369. static void walk_attr_value ();
  370. static void write_attr_get ();
  371. static rtx eliminate_known_true ();
  372. static void write_attr_set ();
  373. static void write_attr_case ();
  374. static void write_attr_value ();
  375. static void write_attr_valueq ();
  376. static void write_upcase ();
  377. static void write_indent ();
  378. static void write_eligible_delay ();
  379. static void write_function_unit_info ();
  380. static void write_complex_function ();
  381. static int n_comma_elts ();
  382. static char *next_comma_elt ();
  383. static struct attr_desc *find_attr ();
  384. static void make_internal_attr ();
  385. static struct attr_value *find_most_used ();
  386. static rtx find_single_value ();
  387. static rtx make_numeric_value ();
  388. static void extend_range ();
  389. char *xrealloc ();
  390. char *xmalloc ();
  391. static void fatal ();
  392.  
  393. #define oballoc(size) obstack_alloc (hash_obstack, size)
  394.  
  395.  
  396. /* Hash table for sharing RTL and strings.  */
  397.  
  398. /* Each hash table slot is a bucket containing a chain of these structures.
  399.    Strings are given negative hash codes; RTL expressions are given positive
  400.    hash codes.  */
  401.  
  402. struct attr_hash
  403. {
  404.   struct attr_hash *next;    /* Next structure in the bucket.  */
  405.   int hashcode;            /* Hash code of this rtx or string.  */
  406.   union
  407.     {
  408.       char *str;        /* The string (negative hash codes) */
  409.       rtx rtl;            /* or the RTL recorded here.  */
  410.     } u;
  411. };
  412.  
  413. /* Now here is the hash table.  When recording an RTL, it is added to
  414.    the slot whose index is the hash code mod the table size.  Note
  415.    that the hash table is used for several kinds of RTL (see attr_rtx)
  416.    and for strings.  While all these live in the same table, they are
  417.    completely independent, and the hash code is computed differently
  418.    for each.  */
  419.  
  420. #define RTL_HASH_SIZE 4093
  421. struct attr_hash *attr_hash_table[RTL_HASH_SIZE];
  422.  
  423. /* Here is how primitive or already-shared RTL's hash
  424.    codes are made.  */
  425. #define RTL_HASH(RTL) ((HOST_WIDE_INT) (RTL) & 0777777)
  426.  
  427. /* Add an entry to the hash table for RTL with hash code HASHCODE.  */
  428.  
  429. static void
  430. attr_hash_add_rtx (hashcode, rtl)
  431.      int hashcode;
  432.      rtx rtl;
  433. {
  434.   register struct attr_hash *h;
  435.  
  436.   h = (struct attr_hash *) obstack_alloc (hash_obstack,
  437.                       sizeof (struct attr_hash));
  438.   h->hashcode = hashcode;
  439.   h->u.rtl = rtl;
  440.   h->next = attr_hash_table[hashcode % RTL_HASH_SIZE];
  441.   attr_hash_table[hashcode % RTL_HASH_SIZE] = h;
  442. }
  443.  
  444. /* Add an entry to the hash table for STRING with hash code HASHCODE.  */
  445.  
  446. static void
  447. attr_hash_add_string (hashcode, str)
  448.      int hashcode;
  449.      char *str;
  450. {
  451.   register struct attr_hash *h;
  452.  
  453.   h = (struct attr_hash *) obstack_alloc (hash_obstack,
  454.                       sizeof (struct attr_hash));
  455.   h->hashcode = -hashcode;
  456.   h->u.str = str;
  457.   h->next = attr_hash_table[hashcode % RTL_HASH_SIZE];
  458.   attr_hash_table[hashcode % RTL_HASH_SIZE] = h;
  459. }
  460.  
  461. /* Generate an RTL expression, but avoid duplicates.
  462.    Set the RTX_INTEGRATED_P flag for these permanent objects.
  463.  
  464.    In some cases we cannot uniquify; then we return an ordinary
  465.    impermanent rtx with RTX_INTEGRATED_P clear.
  466.  
  467.    Args are like gen_rtx, but without the mode:
  468.  
  469.    rtx attr_rtx (code, [element1, ..., elementn])  */
  470.  
  471. /*VARARGS1*/
  472. static rtx
  473. attr_rtx (va_alist)
  474.      va_dcl
  475. {
  476.   va_list p;
  477.   enum rtx_code code;
  478.   register int i;        /* Array indices...            */
  479.   register char *fmt;        /* Current rtx's format...        */
  480.   register rtx rt_val;        /* RTX to return to caller...        */
  481.   int hashcode;
  482.   register struct attr_hash *h;
  483.   struct obstack *old_obstack = rtl_obstack;
  484.  
  485.   va_start (p);
  486.   code = va_arg (p, enum rtx_code);
  487.  
  488.   /* For each of several cases, search the hash table for an existing entry.
  489.      Use that entry if one is found; otherwise create a new RTL and add it
  490.      to the table.  */
  491.  
  492.   if (GET_RTX_CLASS (code) == '1')
  493.     {
  494.       rtx arg0 = va_arg (p, rtx);
  495.  
  496.       /* A permanent object cannot point to impermanent ones.  */
  497.       if (! RTX_INTEGRATED_P (arg0))
  498.     {
  499.       rt_val = rtx_alloc (code);
  500.       XEXP (rt_val, 0) = arg0;
  501.       va_end (p);
  502.       return rt_val;
  503.     }
  504.  
  505.       hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0));
  506.       for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
  507.     if (h->hashcode == hashcode
  508.         && GET_CODE (h->u.rtl) == code
  509.         && XEXP (h->u.rtl, 0) == arg0)
  510.       goto found;
  511.  
  512.       if (h == 0)
  513.     {
  514.       rtl_obstack = hash_obstack;
  515.       rt_val = rtx_alloc (code);
  516.       XEXP (rt_val, 0) = arg0;
  517.     }
  518.     }
  519.   else if (GET_RTX_CLASS (code) == 'c'
  520.        || GET_RTX_CLASS (code) == '2'
  521.        || GET_RTX_CLASS (code) == '<')
  522.     {
  523.       rtx arg0 = va_arg (p, rtx);
  524.       rtx arg1 = va_arg (p, rtx);
  525.  
  526.       /* A permanent object cannot point to impermanent ones.  */
  527.       if (! RTX_INTEGRATED_P (arg0) || ! RTX_INTEGRATED_P (arg1))
  528.     {
  529.       rt_val = rtx_alloc (code);
  530.       XEXP (rt_val, 0) = arg0;
  531.       XEXP (rt_val, 1) = arg1;
  532.       va_end (p);
  533.       return rt_val;
  534.     }
  535.  
  536.       hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0) + RTL_HASH (arg1));
  537.       for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
  538.     if (h->hashcode == hashcode
  539.         && GET_CODE (h->u.rtl) == code
  540.         && XEXP (h->u.rtl, 0) == arg0
  541.         && XEXP (h->u.rtl, 1) == arg1)
  542.       goto found;
  543.  
  544.       if (h == 0)
  545.     {
  546.       rtl_obstack = hash_obstack;
  547.       rt_val = rtx_alloc (code);
  548.       XEXP (rt_val, 0) = arg0;
  549.       XEXP (rt_val, 1) = arg1;
  550.     }
  551.     }
  552.   else if (GET_RTX_LENGTH (code) == 1
  553.        && GET_RTX_FORMAT (code)[0] == 's')
  554.     {
  555.       char * arg0 = va_arg (p, char *);
  556.  
  557.       if (code == SYMBOL_REF)
  558.     arg0 = attr_string (arg0, strlen (arg0));
  559.  
  560.       hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0));
  561.       for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
  562.     if (h->hashcode == hashcode
  563.         && GET_CODE (h->u.rtl) == code
  564.         && XSTR (h->u.rtl, 0) == arg0)
  565.       goto found;
  566.  
  567.       if (h == 0)
  568.     {
  569.       rtl_obstack = hash_obstack;
  570.       rt_val = rtx_alloc (code);
  571.       XSTR (rt_val, 0) = arg0;
  572.     }
  573.     }
  574.   else if (GET_RTX_LENGTH (code) == 2
  575.        && GET_RTX_FORMAT (code)[0] == 's'
  576.        && GET_RTX_FORMAT (code)[1] == 's')
  577.     {
  578.       char *arg0 = va_arg (p, char *);
  579.       char *arg1 = va_arg (p, char *);
  580.  
  581.       hashcode = ((HOST_WIDE_INT) code + RTL_HASH (arg0) + RTL_HASH (arg1));
  582.       for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
  583.     if (h->hashcode == hashcode
  584.         && GET_CODE (h->u.rtl) == code
  585.         && XSTR (h->u.rtl, 0) == arg0
  586.         && XSTR (h->u.rtl, 1) == arg1)
  587.       goto found;
  588.  
  589.       if (h == 0)
  590.     {
  591.       rtl_obstack = hash_obstack;
  592.       rt_val = rtx_alloc (code);
  593.       XSTR (rt_val, 0) = arg0;
  594.       XSTR (rt_val, 1) = arg1;
  595.     }
  596.     }
  597.   else if (code == CONST_INT)
  598.     {
  599.       HOST_WIDE_INT arg0 = va_arg (p, HOST_WIDE_INT);
  600.       if (arg0 == 0)
  601.     return false_rtx;
  602.       if (arg0 == 1)
  603.     return true_rtx;
  604.       goto nohash;
  605.     }
  606.   else
  607.     {
  608.     nohash:
  609.       rt_val = rtx_alloc (code);    /* Allocate the storage space.  */
  610.       
  611.       fmt = GET_RTX_FORMAT (code);    /* Find the right format...  */
  612.       for (i = 0; i < GET_RTX_LENGTH (code); i++)
  613.     {
  614.       switch (*fmt++)
  615.         {
  616.         case '0':        /* Unused field.  */
  617.           break;
  618.  
  619.         case 'i':        /* An integer?  */
  620.           XINT (rt_val, i) = va_arg (p, int);
  621.           break;
  622.  
  623.         case 'w':        /* A wide integer? */
  624.           XWINT (rt_val, i) = va_arg (p, HOST_WIDE_INT);
  625.           break;
  626.  
  627.         case 's':        /* A string?  */
  628.           XSTR (rt_val, i) = va_arg (p, char *);
  629.           break;
  630.  
  631.         case 'e':        /* An expression?  */
  632.         case 'u':        /* An insn?  Same except when printing.  */
  633.           XEXP (rt_val, i) = va_arg (p, rtx);
  634.           break;
  635.  
  636.         case 'E':        /* An RTX vector?  */
  637.           XVEC (rt_val, i) = va_arg (p, rtvec);
  638.           break;
  639.  
  640.         default:
  641.           abort();
  642.         }
  643.     }
  644.       va_end (p);
  645.       return rt_val;
  646.     }
  647.  
  648.   rtl_obstack = old_obstack;
  649.   va_end (p);
  650.   attr_hash_add_rtx (hashcode, rt_val);
  651.   RTX_INTEGRATED_P (rt_val) = 1;
  652.   return rt_val;
  653.  
  654.  found:
  655.   va_end (p);
  656.   return h->u.rtl;
  657. }
  658.  
  659. /* Create a new string printed with the printf line arguments into a space
  660.    of at most LEN bytes:
  661.  
  662.    rtx attr_printf (len, format, [arg1, ..., argn])  */
  663.  
  664. #ifdef HAVE_VPRINTF
  665.  
  666. /*VARARGS2*/
  667. static char *
  668. attr_printf (va_alist)
  669.      va_dcl
  670. {
  671.   va_list p;
  672.   register int len;
  673.   register char *fmt;
  674.   register char *str;
  675.  
  676.   /* Print the string into a temporary location.  */
  677.   va_start (p);
  678.   len = va_arg (p, int);
  679.   str = (char *) alloca (len);
  680.   fmt = va_arg (p, char *);
  681.   vsprintf (str, fmt, p);
  682.   va_end (p);
  683.  
  684.   return attr_string (str, strlen (str));
  685. }
  686.  
  687. #else /* not HAVE_VPRINTF */
  688.  
  689. static char *
  690. attr_printf (len, fmt, arg1, arg2, arg3)
  691.      int len;
  692.      char *fmt;
  693.      char *arg1, *arg2, *arg3; /* also int */
  694. {
  695.   register char *str;
  696.  
  697.   /* Print the string into a temporary location.  */
  698.   str = (char *) alloca (len);
  699.   sprintf (str, fmt, arg1, arg2, arg3);
  700.  
  701.   return attr_string (str, strlen (str));
  702. }
  703. #endif /* not HAVE_VPRINTF */
  704.  
  705. rtx
  706. attr_eq (name, value)
  707.      char *name, *value;
  708. {
  709.   return attr_rtx (EQ_ATTR, attr_string (name, strlen (name)),
  710.            attr_string (value, strlen (value)));
  711. }
  712.  
  713. char *
  714. attr_numeral (n)
  715.      int n;
  716. {
  717.   return XSTR (make_numeric_value (n), 0);
  718. }
  719.  
  720. /* Return a permanent (possibly shared) copy of a string STR (not assumed
  721.    to be null terminated) with LEN bytes.  */
  722.  
  723. static char *
  724. attr_string (str, len)
  725.      char *str;
  726.      int len;
  727. {
  728.   register struct attr_hash *h;
  729.   int hashcode;
  730.   int i;
  731.   register char *new_str;
  732.  
  733.   /* Compute the hash code.  */
  734.   hashcode = (len + 1) * 613 + (unsigned)str[0];
  735.   for (i = 1; i <= len; i += 2)
  736.     hashcode = ((hashcode * 613) + (unsigned)str[i]);
  737.   if (hashcode < 0)
  738.     hashcode = -hashcode;
  739.  
  740.   /* Search the table for the string.  */
  741.   for (h = attr_hash_table[hashcode % RTL_HASH_SIZE]; h; h = h->next)
  742.     if (h->hashcode == -hashcode && h->u.str[0] == str[0]
  743.     && !strncmp (h->u.str, str, len))
  744.       return h->u.str;            /* <-- return if found.  */
  745.  
  746.   /* Not found; create a permanent copy and add it to the hash table.  */
  747.   new_str = (char *) obstack_alloc (hash_obstack, len + 1);
  748.   bcopy (str, new_str, len);
  749.   new_str[len] = '\0';
  750.   attr_hash_add_string (hashcode, new_str);
  751.  
  752.   return new_str;            /* Return the new string.  */
  753. }
  754.  
  755. /* Check two rtx's for equality of contents,
  756.    taking advantage of the fact that if both are hashed
  757.    then they can't be equal unless they are the same object.  */
  758.  
  759. int
  760. attr_equal_p (x, y)
  761.      rtx x, y;
  762. {
  763.   return (x == y || (! (RTX_INTEGRATED_P (x) && RTX_INTEGRATED_P (y))
  764.              && rtx_equal_p (x, y)));
  765. }
  766.  
  767. /* Copy an attribute value expression,
  768.    descending to all depths, but not copying any
  769.    permanent hashed subexpressions.  */
  770.  
  771. rtx
  772. attr_copy_rtx (orig)
  773.      register rtx orig;
  774. {
  775.   register rtx copy;
  776.   register int i, j;
  777.   register RTX_CODE code;
  778.   register char *format_ptr;
  779.  
  780.   /* No need to copy a permanent object.  */
  781.   if (RTX_INTEGRATED_P (orig))
  782.     return orig;
  783.  
  784.   code = GET_CODE (orig);
  785.  
  786.   switch (code)
  787.     {
  788.     case REG:
  789.     case QUEUED:
  790.     case CONST_INT:
  791.     case CONST_DOUBLE:
  792.     case SYMBOL_REF:
  793.     case CODE_LABEL:
  794.     case PC:
  795.     case CC0:
  796.       return orig;
  797.     }
  798.  
  799.   copy = rtx_alloc (code);
  800.   PUT_MODE (copy, GET_MODE (orig));
  801.   copy->in_struct = orig->in_struct;
  802.   copy->volatil = orig->volatil;
  803.   copy->unchanging = orig->unchanging;
  804.   copy->integrated = orig->integrated;
  805.   
  806.   format_ptr = GET_RTX_FORMAT (GET_CODE (copy));
  807.  
  808.   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (copy)); i++)
  809.     {
  810.       switch (*format_ptr++)
  811.     {
  812.     case 'e':
  813.       XEXP (copy, i) = XEXP (orig, i);
  814.       if (XEXP (orig, i) != NULL)
  815.         XEXP (copy, i) = attr_copy_rtx (XEXP (orig, i));
  816.       break;
  817.  
  818.     case 'E':
  819.     case 'V':
  820.       XVEC (copy, i) = XVEC (orig, i);
  821.       if (XVEC (orig, i) != NULL)
  822.         {
  823.           XVEC (copy, i) = rtvec_alloc (XVECLEN (orig, i));
  824.           for (j = 0; j < XVECLEN (copy, i); j++)
  825.         XVECEXP (copy, i, j) = attr_copy_rtx (XVECEXP (orig, i, j));
  826.         }
  827.       break;
  828.  
  829.     case 'n':
  830.     case 'i':
  831.       XINT (copy, i) = XINT (orig, i);
  832.       break;
  833.  
  834.     case 'w':
  835.       XWINT (copy, i) = XWINT (orig, i);
  836.       break;
  837.  
  838.     case 's':
  839.     case 'S':
  840.       XSTR (copy, i) = XSTR (orig, i);
  841.       break;
  842.  
  843.     default:
  844.       abort ();
  845.     }
  846.     }
  847.   return copy;
  848. }
  849.  
  850. /* Given a test expression for an attribute, ensure it is validly formed.
  851.    IS_CONST indicates whether the expression is constant for each compiler
  852.    run (a constant expression may not test any particular insn).
  853.  
  854.    Convert (eq_attr "att" "a1,a2") to (ior (eq_attr ... ) (eq_attrq ..))
  855.    and (eq_attr "att" "!a1") to (not (eq_attr "att" "a1")).  Do the latter
  856.    test first so that (eq_attr "att" "!a1,a2,a3") works as expected.
  857.  
  858.    Update the string address in EQ_ATTR expression to be the same used
  859.    in the attribute (or `alternative_name') to speed up subsequent
  860.    `find_attr' calls and eliminate most `strcmp' calls.
  861.  
  862.    Return the new expression, if any.   */
  863.  
  864. static rtx
  865. check_attr_test (exp, is_const)
  866.      rtx exp;
  867.      int is_const;
  868. {
  869.   struct attr_desc *attr;
  870.   struct attr_value *av;
  871.   char *name_ptr, *p;
  872.   rtx orexp, newexp;
  873.  
  874.   switch (GET_CODE (exp))
  875.     {
  876.     case EQ_ATTR:
  877.       /* Handle negation test.  */
  878.       if (XSTR (exp, 1)[0] == '!')
  879.     return check_attr_test (attr_rtx (NOT,
  880.                       attr_eq (XSTR (exp, 0),
  881.                            &XSTR (exp, 1)[1])),
  882.                 is_const);
  883.  
  884.       else if (n_comma_elts (XSTR (exp, 1)) == 1)
  885.     {
  886.       attr = find_attr (XSTR (exp, 0), 0);
  887.       if (attr == NULL)
  888.         {
  889.           if (! strcmp (XSTR (exp, 0), "alternative"))
  890.         {
  891.           XSTR (exp, 0) = alternative_name;
  892.           /* This can't be simplified any further.  */
  893.           RTX_UNCHANGING_P (exp) = 1;
  894.           return exp;
  895.         }
  896.           else
  897.         fatal ("Unknown attribute `%s' in EQ_ATTR", XEXP (exp, 0));
  898.         }
  899.  
  900.       if (is_const && ! attr->is_const)
  901.         fatal ("Constant expression uses insn attribute `%s' in EQ_ATTR",
  902.            XEXP (exp, 0));
  903.  
  904.       /* Copy this just to make it permanent,
  905.          so expressions using it can be permanent too.  */
  906.       exp = attr_eq (XSTR (exp, 0), XSTR (exp, 1));
  907.  
  908.       /* It shouldn't be possible to simplify the value given to a
  909.          constant attribute, so don't expand this until it's time to
  910.          write the test expression.  */           
  911.       if (attr->is_const)
  912.         RTX_UNCHANGING_P (exp) = 1;
  913.  
  914.       if (attr->is_numeric)
  915.         {
  916.           for (p = XSTR (exp, 1); *p; p++)
  917.         if (*p < '0' || *p > '9')
  918.            fatal ("Attribute `%s' takes only numeric values", 
  919.               XEXP (exp, 0));
  920.         }
  921.       else
  922.         {
  923.           for (av = attr->first_value; av; av = av->next)
  924.         if (GET_CODE (av->value) == CONST_STRING
  925.             && ! strcmp (XSTR (exp, 1), XSTR (av->value, 0)))
  926.           break;
  927.  
  928.           if (av == NULL)
  929.         fatal ("Unknown value `%s' for `%s' attribute",
  930.                XEXP (exp, 1), XEXP (exp, 0));
  931.         }
  932.     }
  933.       else
  934.     {
  935.       /* Make an IOR tree of the possible values.  */
  936.       orexp = false_rtx;
  937.       name_ptr = XSTR (exp, 1);
  938.       while ((p = next_comma_elt (&name_ptr)) != NULL)
  939.         {
  940.           newexp = attr_eq (XSTR (exp, 0), p);
  941.           orexp = insert_right_side (IOR, orexp, newexp, -2);
  942.         }
  943.  
  944.       return check_attr_test (orexp, is_const);
  945.     }
  946.       break;
  947.  
  948.     case CONST_INT:
  949.       /* Either TRUE or FALSE.  */
  950.       if (XWINT (exp, 0))
  951.     return true_rtx;
  952.       else
  953.     return false_rtx;
  954.  
  955.     case IOR:
  956.     case AND:
  957.       XEXP (exp, 0) = check_attr_test (XEXP (exp, 0), is_const);
  958.       XEXP (exp, 1) = check_attr_test (XEXP (exp, 1), is_const);
  959.       break;
  960.  
  961.     case NOT:
  962.       XEXP (exp, 0) = check_attr_test (XEXP (exp, 0), is_const);
  963.       break;
  964.  
  965.     case MATCH_OPERAND:
  966.       if (is_const)
  967.     fatal ("RTL operator \"%s\" not valid in constant attribute test",
  968.            GET_RTX_NAME (MATCH_OPERAND));
  969.       /* These cases can't be simplified.  */
  970.       RTX_UNCHANGING_P (exp) = 1;
  971.       break;
  972.  
  973.     case LE:  case LT:  case GT:  case GE:
  974.     case LEU: case LTU: case GTU: case GEU:
  975.     case NE:  case EQ:
  976.       if (GET_CODE (XEXP (exp, 0)) == SYMBOL_REF
  977.       && GET_CODE (XEXP (exp, 1)) == SYMBOL_REF)
  978.     exp = attr_rtx (GET_CODE (exp),
  979.             attr_rtx (SYMBOL_REF, XSTR (XEXP (exp, 0), 0)),
  980.             attr_rtx (SYMBOL_REF, XSTR (XEXP (exp, 1), 0)));
  981.       /* These cases can't be simplified.  */
  982.       RTX_UNCHANGING_P (exp) = 1;
  983.       break;
  984.  
  985.     case SYMBOL_REF:
  986.       if (is_const)
  987.     {
  988.       /* These cases are valid for constant attributes, but can't be
  989.          simplified.  */
  990.       exp = attr_rtx (SYMBOL_REF, XSTR (exp, 0));
  991.       RTX_UNCHANGING_P (exp) = 1;
  992.       break;
  993.     }
  994.     default:
  995.       fatal ("RTL operator \"%s\" not valid in attribute test",
  996.          GET_RTX_NAME (GET_CODE (exp)));
  997.     }
  998.  
  999.   return exp;
  1000. }
  1001.  
  1002. /* Given an expression, ensure that it is validly formed and that all named
  1003.    attribute values are valid for the given attribute.  Issue a fatal error
  1004.    if not.  If no attribute is specified, assume a numeric attribute.
  1005.  
  1006.    Return a perhaps modified replacement expression for the value.  */
  1007.  
  1008. static rtx
  1009. check_attr_value (exp, attr)
  1010.      rtx exp;
  1011.      struct attr_desc *attr;
  1012. {
  1013.   struct attr_value *av;
  1014.   char *p;
  1015.   int i;
  1016.  
  1017.   switch (GET_CODE (exp))
  1018.     {
  1019.     case CONST_INT:
  1020.       if (attr && ! attr->is_numeric)
  1021.     fatal ("CONST_INT not valid for non-numeric `%s' attribute",
  1022.            attr->name);
  1023.  
  1024.       if (INTVAL (exp) < 0)
  1025.     fatal ("Negative numeric value specified for `%s' attribute",
  1026.            attr->name);
  1027.  
  1028.       break;
  1029.  
  1030.     case CONST_STRING:
  1031.       if (! strcmp (XSTR (exp, 0), "*"))
  1032.     break;
  1033.  
  1034.       if (attr == 0 || attr->is_numeric)
  1035.     {
  1036.       p = XSTR (exp, 0);
  1037.       if (attr && attr->negative_ok && *p == '-')
  1038.         p++;
  1039.       for (; *p; p++)
  1040.         if (*p > '9' || *p < '0')
  1041.           fatal ("Non-numeric value for numeric `%s' attribute",
  1042.              attr ? attr->name : "internal");
  1043.       break;
  1044.     }
  1045.  
  1046.       for (av = attr->first_value; av; av = av->next)
  1047.     if (GET_CODE (av->value) == CONST_STRING
  1048.         && ! strcmp (XSTR (av->value, 0), XSTR (exp, 0)))
  1049.       break;
  1050.  
  1051.       if (av == NULL)
  1052.     fatal ("Unknown value `%s' for `%s' attribute",
  1053.            XSTR (exp, 0), attr ? attr->name : "internal");
  1054.  
  1055.       break;
  1056.  
  1057.     case IF_THEN_ELSE:
  1058.       XEXP (exp, 0) = check_attr_test (XEXP (exp, 0),
  1059.                        attr ? attr->is_const : 0);
  1060.       XEXP (exp, 1) = check_attr_value (XEXP (exp, 1), attr);
  1061.       XEXP (exp, 2) = check_attr_value (XEXP (exp, 2), attr);
  1062.       break;
  1063.  
  1064.     case COND:
  1065.       if (XVECLEN (exp, 0) % 2 != 0)
  1066.     fatal ("First operand of COND must have even length");
  1067.  
  1068.       for (i = 0; i < XVECLEN (exp, 0); i += 2)
  1069.     {
  1070.       XVECEXP (exp, 0, i) = check_attr_test (XVECEXP (exp, 0, i),
  1071.                          attr ? attr->is_const : 0);
  1072.       XVECEXP (exp, 0, i + 1)
  1073.         = check_attr_value (XVECEXP (exp, 0, i + 1), attr);
  1074.     }
  1075.  
  1076.       XEXP (exp, 1) = check_attr_value (XEXP (exp, 1), attr);
  1077.       break;
  1078.  
  1079.     case SYMBOL_REF:
  1080.       if (attr && attr->is_const)
  1081.     /* A constant SYMBOL_REF is valid as a constant attribute test and
  1082.        is expanded later by make_canonical into a COND.  */
  1083.     return attr_rtx (SYMBOL_REF, XSTR (exp, 0));
  1084.       /* Otherwise, fall through... */
  1085.  
  1086.     default:
  1087.       fatal ("Illegal operation `%s' for attribute value",
  1088.          GET_RTX_NAME (GET_CODE (exp)));
  1089.     }
  1090.  
  1091.   return exp;
  1092. }
  1093.  
  1094. /* Given an SET_ATTR_ALTERNATIVE expression, convert to the canonical SET.
  1095.    It becomes a COND with each test being (eq_attr "alternative "n") */
  1096.  
  1097. static rtx
  1098. convert_set_attr_alternative (exp, num_alt, insn_code, insn_index)
  1099.      rtx exp;
  1100.      int num_alt;
  1101.      int insn_code, insn_index;
  1102. {
  1103.   rtx condexp;
  1104.   int i;
  1105.  
  1106.   if (XVECLEN (exp, 1) != num_alt)
  1107.     fatal ("Bad number of entries in SET_ATTR_ALTERNATIVE for insn %d",
  1108.        insn_index);
  1109.  
  1110.   /* Make a COND with all tests but the last.  Select the last value via the
  1111.      default.  */
  1112.   condexp = rtx_alloc (COND);
  1113.   XVEC (condexp, 0) = rtvec_alloc ((num_alt - 1) * 2);
  1114.  
  1115.   for (i = 0; i < num_alt - 1; i++)
  1116.     {
  1117.       char *p;
  1118.       p = attr_numeral (i);
  1119.  
  1120.       XVECEXP (condexp, 0, 2 * i) = attr_eq (alternative_name, p);
  1121. #if 0
  1122.       /* Sharing this EQ_ATTR rtl causes trouble.  */   
  1123.       XVECEXP (condexp, 0, 2 * i) = rtx_alloc (EQ_ATTR);
  1124.       XSTR (XVECEXP (condexp, 0, 2 * i), 0) = alternative_name;
  1125.       XSTR (XVECEXP (condexp, 0, 2 * i), 1) = p;
  1126. #endif
  1127.       XVECEXP (condexp, 0, 2 * i + 1) = XVECEXP (exp, 1, i);
  1128.     }
  1129.  
  1130.   XEXP (condexp, 1) = XVECEXP (exp, 1, i);
  1131.  
  1132.   return attr_rtx (SET, attr_rtx (ATTR, XSTR (exp, 0)), condexp);
  1133. }
  1134.  
  1135. /* Given a SET_ATTR, convert to the appropriate SET.  If a comma-separated
  1136.    list of values is given, convert to SET_ATTR_ALTERNATIVE first.  */
  1137.  
  1138. static rtx
  1139. convert_set_attr (exp, num_alt, insn_code, insn_index)
  1140.      rtx exp;
  1141.      int num_alt;
  1142.      int insn_code, insn_index;
  1143. {
  1144.   rtx newexp;
  1145.   char *name_ptr;
  1146.   char *p;
  1147.   int n;
  1148.  
  1149.   /* See how many alternative specified.  */
  1150.   n = n_comma_elts (XSTR (exp, 1));
  1151.   if (n == 1)
  1152.     return attr_rtx (SET,
  1153.              attr_rtx (ATTR, XSTR (exp, 0)),
  1154.              attr_rtx (CONST_STRING, XSTR (exp, 1)));
  1155.  
  1156.   newexp = rtx_alloc (SET_ATTR_ALTERNATIVE);
  1157.   XSTR (newexp, 0) = XSTR (exp, 0);
  1158.   XVEC (newexp, 1) = rtvec_alloc (n);
  1159.  
  1160.   /* Process each comma-separated name.  */
  1161.   name_ptr = XSTR (exp, 1);
  1162.   n = 0;
  1163.   while ((p = next_comma_elt (&name_ptr)) != NULL)
  1164.     XVECEXP (newexp, 1, n++) = attr_rtx (CONST_STRING, p);
  1165.  
  1166.   return convert_set_attr_alternative (newexp, num_alt, insn_code, insn_index);
  1167. }
  1168.  
  1169. /* Scan all definitions, checking for validity.  Also, convert any SET_ATTR
  1170.    and SET_ATTR_ALTERNATIVE expressions to the corresponding SET
  1171.    expressions. */
  1172.  
  1173. static void
  1174. check_defs ()
  1175. {
  1176.   struct insn_def *id;
  1177.   struct attr_desc *attr;
  1178.   int i;
  1179.   rtx value;
  1180.  
  1181.   for (id = defs; id; id = id->next)
  1182.     {
  1183.       if (XVEC (id->def, id->vec_idx) == NULL)
  1184.     continue;
  1185.  
  1186.       for (i = 0; i < XVECLEN (id->def, id->vec_idx); i++)
  1187.     {
  1188.       value = XVECEXP (id->def, id->vec_idx, i);
  1189.       switch (GET_CODE (value))
  1190.         {
  1191.         case SET:
  1192.           if (GET_CODE (XEXP (value, 0)) != ATTR)
  1193.         fatal ("Bad attribute set in pattern %d", id->insn_index);
  1194.           break;
  1195.  
  1196.         case SET_ATTR_ALTERNATIVE:
  1197.           value = convert_set_attr_alternative (value,
  1198.                             id->num_alternatives,
  1199.                             id->insn_code,
  1200.                             id->insn_index);
  1201.           break;
  1202.  
  1203.         case SET_ATTR:
  1204.           value = convert_set_attr (value, id->num_alternatives,
  1205.                     id->insn_code, id->insn_index);
  1206.           break;
  1207.  
  1208.         default:
  1209.           fatal ("Invalid attribute code `%s' for pattern %d",
  1210.              GET_RTX_NAME (GET_CODE (value)), id->insn_index);
  1211.         }
  1212.  
  1213.       if ((attr = find_attr (XSTR (XEXP (value, 0), 0), 0)) == NULL)
  1214.         fatal ("Unknown attribute `%s' for pattern number %d",
  1215.            XSTR (XEXP (value, 0), 0), id->insn_index);
  1216.  
  1217.       XVECEXP (id->def, id->vec_idx, i) = value;
  1218.       XEXP (value, 1) = check_attr_value (XEXP (value, 1), attr);
  1219.     }
  1220.     }
  1221. }
  1222.  
  1223. /* Given a constant SYMBOL_REF expression, convert to a COND that
  1224.    explicitly tests each enumerated value.  */
  1225.  
  1226. static rtx
  1227. convert_const_symbol_ref (exp, attr)
  1228.      rtx exp;
  1229.      struct attr_desc *attr;
  1230. {
  1231.   rtx condexp;
  1232.   struct attr_value *av;
  1233.   int i;
  1234.   int num_alt = 0;
  1235.  
  1236.   for (av = attr->first_value; av; av = av->next)
  1237.     num_alt++;
  1238.  
  1239.   /* Make a COND with all tests but the last, and in the original order.
  1240.      Select the last value via the default.  Note that the attr values
  1241.      are constructed in reverse order.  */
  1242.  
  1243.   condexp = rtx_alloc (COND);
  1244.   XVEC (condexp, 0) = rtvec_alloc ((num_alt - 1) * 2);
  1245.   av = attr->first_value;
  1246.   XEXP (condexp, 1) = av->value;
  1247.  
  1248.   for (i = num_alt - 2; av = av->next, i >= 0; i--)
  1249.     {
  1250.       char *p, *string;
  1251.       rtx value;
  1252.  
  1253.       string = p = (char *) oballoc (2
  1254.                      + strlen (attr->name)
  1255.                      + strlen (XSTR (av->value, 0)));
  1256.       strcpy (p, attr->name);
  1257.       strcat (p, "_");
  1258.       strcat (p, XSTR (av->value, 0));
  1259.       for (; *p != '\0'; p++)
  1260.     if (*p >= 'a' && *p <= 'z')
  1261.       *p -= 'a' - 'A';
  1262.  
  1263.       value = attr_rtx (SYMBOL_REF, string);
  1264.       RTX_UNCHANGING_P (value) = 1;
  1265.       
  1266.       XVECEXP (condexp, 0, 2 * i) = attr_rtx (EQ, exp, value);
  1267.  
  1268.       XVECEXP (condexp, 0, 2 * i + 1) = av->value;
  1269.     }
  1270.  
  1271.   return condexp;
  1272. }
  1273.  
  1274. /* Given a valid expression for an attribute value, remove any IF_THEN_ELSE
  1275.    expressions by converting them into a COND.  This removes cases from this
  1276.    program.  Also, replace an attribute value of "*" with the default attribute
  1277.    value.  */
  1278.  
  1279. static rtx
  1280. make_canonical (attr, exp)
  1281.      struct attr_desc *attr;
  1282.      rtx exp;
  1283. {
  1284.   int i;
  1285.   rtx newexp;
  1286.  
  1287.   switch (GET_CODE (exp))
  1288.     {
  1289.     case CONST_INT:
  1290.       exp = make_numeric_value (INTVAL (exp));
  1291.       break;
  1292.  
  1293.     case CONST_STRING:
  1294.       if (! strcmp (XSTR (exp, 0), "*"))
  1295.     {
  1296.       if (attr == 0 || attr->default_val == 0)
  1297.         fatal ("(attr_value \"*\") used in invalid context.");
  1298.       exp = attr->default_val->value;
  1299.     }
  1300.  
  1301.       break;
  1302.  
  1303.     case SYMBOL_REF:
  1304.       if (!attr->is_const || RTX_UNCHANGING_P (exp))
  1305.     break;
  1306.       /* The SYMBOL_REF is constant for a given run, so mark it as unchanging.
  1307.      This makes the COND something that won't be considered an arbitrary
  1308.      expression by walk_attr_value.  */
  1309.       RTX_UNCHANGING_P (exp) = 1;
  1310.       exp = convert_const_symbol_ref (exp, attr);
  1311.       RTX_UNCHANGING_P (exp) = 1;
  1312.       exp = check_attr_value (exp, attr);
  1313.       /* Goto COND case since this is now a COND.  Note that while the
  1314.          new expression is rescanned, all symbol_ref notes are mared as
  1315.      unchanging.  */
  1316.       goto cond;
  1317.  
  1318.     case IF_THEN_ELSE:
  1319.       newexp = rtx_alloc (COND);
  1320.       XVEC (newexp, 0) = rtvec_alloc (2);
  1321.       XVECEXP (newexp, 0, 0) = XEXP (exp, 0);
  1322.       XVECEXP (newexp, 0, 1) = XEXP (exp, 1);
  1323.  
  1324.       XEXP (newexp, 1) = XEXP (exp, 2);
  1325.  
  1326.       exp = newexp;
  1327.       /* Fall through to COND case since this is now a COND.  */
  1328.  
  1329.     case COND:
  1330.     cond:
  1331.       {
  1332.     int allsame = 1;
  1333.     rtx defval;
  1334.  
  1335.     /* First, check for degenerate COND. */
  1336.     if (XVECLEN (exp, 0) == 0)
  1337.       return make_canonical (attr, XEXP (exp, 1));
  1338.     defval = XEXP (exp, 1) = make_canonical (attr, XEXP (exp, 1));
  1339.  
  1340.     for (i = 0; i < XVECLEN (exp, 0); i += 2)
  1341.       {
  1342.         XVECEXP (exp, 0, i) = copy_boolean (XVECEXP (exp, 0, i));
  1343.         XVECEXP (exp, 0, i + 1)
  1344.           = make_canonical (attr, XVECEXP (exp, 0, i + 1));
  1345.         if (! rtx_equal_p (XVECEXP (exp, 0, i + 1), defval))
  1346.           allsame = 0;
  1347.       }
  1348.     if (allsame)
  1349.       return defval;
  1350.     break;
  1351.       }
  1352.     }
  1353.  
  1354.   return exp;
  1355. }
  1356.  
  1357. static rtx
  1358. copy_boolean (exp)
  1359.      rtx exp;
  1360. {
  1361.   if (GET_CODE (exp) == AND || GET_CODE (exp) == IOR)
  1362.     return attr_rtx (GET_CODE (exp), copy_boolean (XEXP (exp, 0)),
  1363.              copy_boolean (XEXP (exp, 1)));
  1364.   return exp;
  1365. }
  1366.  
  1367. /* Given a value and an attribute description, return a `struct attr_value *'
  1368.    that represents that value.  This is either an existing structure, if the
  1369.    value has been previously encountered, or a newly-created structure.
  1370.  
  1371.    `insn_code' is the code of an insn whose attribute has the specified
  1372.    value (-2 if not processing an insn).  We ensure that all insns for
  1373.    a given value have the same number of alternatives if the value checks
  1374.    alternatives.  */
  1375.  
  1376. static struct attr_value *
  1377. get_attr_value (value, attr, insn_code)
  1378.      rtx value;
  1379.      struct attr_desc *attr;
  1380.      int insn_code;
  1381. {
  1382.   struct attr_value *av;
  1383.   int num_alt = 0;
  1384.  
  1385.   value = make_canonical (attr, value);
  1386.   if (compares_alternatives_p (value))
  1387.     {
  1388.       if (insn_code < 0 || insn_alternatives == NULL)
  1389.     fatal ("(eq_attr \"alternatives\" ...) used in non-insn context");
  1390.       else
  1391.     num_alt = insn_alternatives[insn_code];
  1392.     }
  1393.  
  1394.   for (av = attr->first_value; av; av = av->next)
  1395.     if (rtx_equal_p (value, av->value)
  1396.     && (num_alt == 0 || av->first_insn == NULL
  1397.         || insn_alternatives[av->first_insn->insn_code]))
  1398.       return av;
  1399.  
  1400.   av = (struct attr_value *) oballoc (sizeof (struct attr_value));
  1401.   av->value = value;
  1402.   av->next = attr->first_value;
  1403.   attr->first_value = av;
  1404.   av->first_insn = NULL;
  1405.   av->num_insns = 0;
  1406.   av->has_asm_insn = 0;
  1407.  
  1408.   return av;
  1409. }
  1410.  
  1411. /* After all DEFINE_DELAYs have been read in, create internal attributes
  1412.    to generate the required routines.
  1413.  
  1414.    First, we compute the number of delay slots for each insn (as a COND of
  1415.    each of the test expressions in DEFINE_DELAYs).  Then, if more than one
  1416.    delay type is specified, we compute a similar function giving the
  1417.    DEFINE_DELAY ordinal for each insn.
  1418.  
  1419.    Finally, for each [DEFINE_DELAY, slot #] pair, we compute an attribute that
  1420.    tells whether a given insn can be in that delay slot.
  1421.  
  1422.    Normal attribute filling and optimization expands these to contain the
  1423.    information needed to handle delay slots.  */
  1424.  
  1425. static void
  1426. expand_delays ()
  1427. {
  1428.   struct delay_desc *delay;
  1429.   rtx condexp;
  1430.   rtx newexp;
  1431.   int i;
  1432.   char *p;
  1433.  
  1434.   /* First, generate data for `num_delay_slots' function.  */
  1435.  
  1436.   condexp = rtx_alloc (COND);
  1437.   XVEC (condexp, 0) = rtvec_alloc (num_delays * 2);
  1438.   XEXP (condexp, 1) = make_numeric_value (0);
  1439.  
  1440.   for (i = 0, delay = delays; delay; i += 2, delay = delay->next)
  1441.     {
  1442.       XVECEXP (condexp, 0, i) = XEXP (delay->def, 0);
  1443.       XVECEXP (condexp, 0, i + 1)
  1444.     = make_numeric_value (XVECLEN (delay->def, 1) / 3);
  1445.     }
  1446.  
  1447.   make_internal_attr ("*num_delay_slots", condexp, 0);
  1448.  
  1449.   /* If more than one delay type, do the same for computing the delay type.  */
  1450.   if (num_delays > 1)
  1451.     {
  1452.       condexp = rtx_alloc (COND);
  1453.       XVEC (condexp, 0) = rtvec_alloc (num_delays * 2);
  1454.       XEXP (condexp, 1) = make_numeric_value (0);
  1455.  
  1456.       for (i = 0, delay = delays; delay; i += 2, delay = delay->next)
  1457.     {
  1458.       XVECEXP (condexp, 0, i) = XEXP (delay->def, 0);
  1459.       XVECEXP (condexp, 0, i + 1) = make_numeric_value (delay->num);
  1460.     }
  1461.  
  1462.       make_internal_attr ("*delay_type", condexp, 1);
  1463.     }
  1464.  
  1465.   /* For each delay possibility and delay slot, compute an eligibility
  1466.      attribute for non-annulled insns and for each type of annulled (annul
  1467.      if true and annul if false).  */
  1468.  for (delay = delays; delay; delay = delay->next)
  1469.    {
  1470.      for (i = 0; i < XVECLEN (delay->def, 1); i += 3)
  1471.        {
  1472.      condexp = XVECEXP (delay->def, 1, i);
  1473.      if (condexp == 0) condexp = false_rtx;
  1474.      newexp = attr_rtx (IF_THEN_ELSE, condexp,
  1475.                 make_numeric_value (1), make_numeric_value (0));
  1476.  
  1477.      p = attr_printf (sizeof ("*delay__") + MAX_DIGITS*2, "*delay_%d_%d",
  1478.               delay->num, i / 3);
  1479.      make_internal_attr (p, newexp, 1);
  1480.  
  1481.      if (have_annul_true)
  1482.        {
  1483.          condexp = XVECEXP (delay->def, 1, i + 1);
  1484.          if (condexp == 0) condexp = false_rtx;
  1485.          newexp = attr_rtx (IF_THEN_ELSE, condexp,
  1486.                 make_numeric_value (1),
  1487.                 make_numeric_value (0));
  1488.          p = attr_printf (sizeof ("*annul_true__") + MAX_DIGITS*2,
  1489.                   "*annul_true_%d_%d", delay->num, i / 3);
  1490.          make_internal_attr (p, newexp, 1);
  1491.        }
  1492.  
  1493.      if (have_annul_false)
  1494.        {
  1495.          condexp = XVECEXP (delay->def, 1, i + 2);
  1496.          if (condexp == 0) condexp = false_rtx;
  1497.          newexp = attr_rtx (IF_THEN_ELSE, condexp,
  1498.                 make_numeric_value (1),
  1499.                 make_numeric_value (0));
  1500.          p = attr_printf (sizeof ("*annul_false__") + MAX_DIGITS*2,
  1501.                   "*annul_false_%d_%d", delay->num, i / 3);
  1502.          make_internal_attr (p, newexp, 1);
  1503.        }
  1504.        }
  1505.    }
  1506. }
  1507.  
  1508. /* This function is given a left and right side expression and an operator.
  1509.    Each side is a conditional expression, each alternative of which has a
  1510.    numerical value.  The function returns another conditional expression
  1511.    which, for every possible set of condition values, returns a value that is
  1512.    the operator applied to the values of the two sides.
  1513.  
  1514.    Since this is called early, it must also support IF_THEN_ELSE.  */
  1515.  
  1516. static rtx
  1517. operate_exp (op, left, right)
  1518.      enum operator op;
  1519.      rtx left, right;
  1520. {
  1521.   int left_value, right_value;
  1522.   rtx newexp;
  1523.   int i;
  1524.  
  1525.   /* If left is a string, apply operator to it and the right side.  */
  1526.   if (GET_CODE (left) == CONST_STRING)
  1527.     {
  1528.       /* If right is also a string, just perform the operation.  */
  1529.       if (GET_CODE (right) == CONST_STRING)
  1530.     {
  1531.       left_value = atoi (XSTR (left, 0));
  1532.       right_value = atoi (XSTR (right, 0));
  1533.       switch (op)
  1534.         {
  1535.         case PLUS_OP:
  1536.           i = left_value + right_value;
  1537.           break;
  1538.  
  1539.         case MINUS_OP:
  1540.           i = left_value - right_value;
  1541.           break;
  1542.  
  1543.         case POS_MINUS_OP:  /* The positive part of LEFT - RIGHT.  */
  1544.           if (left_value > right_value)
  1545.         i = left_value - right_value;
  1546.           else
  1547.         i = 0;
  1548.           break;
  1549.  
  1550.         case OR_OP:
  1551.           i = left_value | right_value;
  1552.           break;
  1553.  
  1554.         case EQ_OP:
  1555.           i = left_value == right_value;
  1556.           break;
  1557.  
  1558.         case RANGE_OP:
  1559.           i = (left_value << (HOST_BITS_PER_INT / 2)) | right_value;
  1560.           break;
  1561.  
  1562.         case MAX_OP:
  1563.           if (left_value > right_value)
  1564.         i = left_value;
  1565.           else
  1566.         i = right_value;
  1567.           break;
  1568.  
  1569.         case MIN_OP:
  1570.           if (left_value < right_value)
  1571.         i = left_value;
  1572.           else
  1573.         i = right_value;
  1574.           break;
  1575.  
  1576.         default:
  1577.           abort ();
  1578.         }
  1579.  
  1580.       return make_numeric_value (i);
  1581.     }
  1582.       else if (GET_CODE (right) == IF_THEN_ELSE)
  1583.     {
  1584.       /* Apply recursively to all values within.  */
  1585.       rtx newleft = operate_exp (op, left, XEXP (right, 1));
  1586.       rtx newright = operate_exp (op, left, XEXP (right, 2));
  1587.       if (rtx_equal_p (newleft, newright))
  1588.         return newleft;
  1589.       return attr_rtx (IF_THEN_ELSE, XEXP (right, 0), newleft, newright);
  1590.     }
  1591.       else if (GET_CODE (right) == COND)
  1592.     {
  1593.       int allsame = 1;
  1594.       rtx defval;
  1595.  
  1596.       newexp = rtx_alloc (COND);
  1597.       XVEC (newexp, 0) = rtvec_alloc (XVECLEN (right, 0));
  1598.       defval = XEXP (newexp, 1) = operate_exp (op, left, XEXP (right, 1));
  1599.  
  1600.       for (i = 0; i < XVECLEN (right, 0); i += 2)
  1601.         {
  1602.           XVECEXP (newexp, 0, i) = XVECEXP (right, 0, i);
  1603.           XVECEXP (newexp, 0, i + 1)
  1604.         = operate_exp (op, left, XVECEXP (right, 0, i + 1));
  1605.           if (! rtx_equal_p (XVECEXP (newexp, 0, i + 1),
  1606.                  defval))     
  1607.         allsame = 0;
  1608.         }
  1609.  
  1610.       /* If the resulting cond is trivial (all alternatives
  1611.          give the same value), optimize it away.  */
  1612.       if (allsame)
  1613.         {
  1614.           obstack_free (rtl_obstack, newexp);
  1615.           return operate_exp (op, left, XEXP (right, 1));
  1616.         }
  1617.  
  1618.       /* If the result is the same as the RIGHT operand,
  1619.          just use that.  */
  1620.       if (rtx_equal_p (newexp, right))
  1621.         {
  1622.           obstack_free (rtl_obstack, newexp);
  1623.           return right;
  1624.         }
  1625.  
  1626.       return newexp;
  1627.     }
  1628.       else
  1629.     fatal ("Badly formed attribute value");
  1630.     }
  1631.  
  1632.   /* Otherwise, do recursion the other way.  */
  1633.   else if (GET_CODE (left) == IF_THEN_ELSE)
  1634.     {
  1635.       rtx newleft = operate_exp (op, XEXP (left, 1), right);
  1636.       rtx newright = operate_exp (op, XEXP (left, 2), right);
  1637.       if (rtx_equal_p (newleft, newright))
  1638.     return newleft;
  1639.       return attr_rtx (IF_THEN_ELSE, XEXP (left, 0), newleft, newright);
  1640.     }
  1641.   else if (GET_CODE (left) == COND)
  1642.     {
  1643.       int allsame = 1;
  1644.       rtx defval;
  1645.  
  1646.       newexp = rtx_alloc (COND);
  1647.       XVEC (newexp, 0) = rtvec_alloc (XVECLEN (left, 0));
  1648.       defval = XEXP (newexp, 1) = operate_exp (op, XEXP (left, 1), right);
  1649.  
  1650.       for (i = 0; i < XVECLEN (left, 0); i += 2)
  1651.     {
  1652.       XVECEXP (newexp, 0, i) = XVECEXP (left, 0, i);
  1653.       XVECEXP (newexp, 0, i + 1)
  1654.         = operate_exp (op, XVECEXP (left, 0, i + 1), right);
  1655.       if (! rtx_equal_p (XVECEXP (newexp, 0, i + 1),
  1656.                  defval))     
  1657.         allsame = 0;
  1658.     }
  1659.  
  1660.       /* If the cond is trivial (all alternatives give the same value),
  1661.      optimize it away.  */
  1662.       if (allsame)
  1663.     {
  1664.       obstack_free (rtl_obstack, newexp);
  1665.       return operate_exp (op, XEXP (left, 1), right);
  1666.     }
  1667.  
  1668.       /* If the result is the same as the LEFT operand,
  1669.      just use that.  */
  1670.       if (rtx_equal_p (newexp, left))
  1671.     {
  1672.       obstack_free (rtl_obstack, newexp);
  1673.       return left;
  1674.     }
  1675.  
  1676.       return newexp;
  1677.     }
  1678.  
  1679.   else
  1680.     fatal ("Badly formed attribute value.");
  1681.   /* NOTREACHED */
  1682.   return NULL;
  1683. }
  1684.  
  1685. /* Once all attributes and DEFINE_FUNCTION_UNITs have been read, we
  1686.    construct a number of attributes.
  1687.  
  1688.    The first produces a function `function_units_used' which is given an
  1689.    insn and produces an encoding showing which function units are required
  1690.    for the execution of that insn.  If the value is non-negative, the insn
  1691.    uses that unit; otherwise, the value is a one's compliment mask of units
  1692.    used.
  1693.  
  1694.    The second produces a function `result_ready_cost' which is used to
  1695.    determine the time that the result of an insn will be ready and hence
  1696.    a worst-case schedule.
  1697.  
  1698.    Both of these produce quite complex expressions which are then set as the
  1699.    default value of internal attributes.  Normal attribute simplification
  1700.    should produce reasonable expressions.
  1701.  
  1702.    For each unit, a `<name>_unit_ready_cost' function will take an
  1703.    insn and give the delay until that unit will be ready with the result
  1704.    and a `<name>_unit_conflict_cost' function is given an insn already
  1705.    executing on the unit and a candidate to execute and will give the
  1706.    cost from the time the executing insn started until the candidate
  1707.    can start (ignore limitations on the number of simultaneous insns).
  1708.  
  1709.    For each unit, a `<name>_unit_blockage' function is given an insn
  1710.    already executing on the unit and a candidate to execute and will
  1711.    give the delay incurred due to function unit conflicts.  The range of
  1712.    blockage cost values for a given executing insn is given by the
  1713.    `<name>_unit_blockage_range' function.  These values are encoded in
  1714.    an int where the upper half gives the minimum value and the lower
  1715.    half gives the maximum value.  */
  1716.  
  1717. static void
  1718. expand_units ()
  1719. {
  1720.   struct function_unit *unit, **unit_num;
  1721.   struct function_unit_op *op, **op_array, ***unit_ops;
  1722.   rtx unitsmask;
  1723.   rtx readycost;
  1724.   rtx newexp;
  1725.   char *str;
  1726.   int i, j, u, num, nvalues;
  1727.  
  1728.   /* Rebuild the condition for the unit to share the RTL expressions.
  1729.      Sharing is required by simplify_by_exploding.  Build the issue delay
  1730.      expressions.  Validate the expressions we were given for the conditions
  1731.      and conflict vector.  Then make attributes for use in the conflict
  1732.      function.  */
  1733.  
  1734.   for (unit = units; unit; unit = unit->next)
  1735.     {
  1736.       rtx min_issue = make_numeric_value (unit->issue_delay.min);
  1737.  
  1738.       unit->condexp = check_attr_test (unit->condexp, 0);
  1739.  
  1740.       for (op = unit->ops; op; op = op->next)
  1741.     {
  1742.       rtx issue_delay = make_numeric_value (op->issue_delay);
  1743.       rtx issue_exp = issue_delay;
  1744.  
  1745.       /* Build, validate, and simplify the issue delay expression.  */
  1746.       if (op->conflict_exp != true_rtx)
  1747.         issue_exp = attr_rtx (IF_THEN_ELSE, op->conflict_exp,
  1748.                   issue_exp, make_numeric_value (0));
  1749.       issue_exp = check_attr_value (make_canonical (NULL_ATTR,
  1750.                             issue_exp),
  1751.                     NULL_ATTR);
  1752.       issue_exp = simplify_knowing (issue_exp, unit->condexp);
  1753.       op->issue_exp = issue_exp;
  1754.  
  1755.       /* Make an attribute for use in the conflict function if needed.  */
  1756.       unit->needs_conflict_function = (unit->issue_delay.min
  1757.                        != unit->issue_delay.max);
  1758.       if (unit->needs_conflict_function)
  1759.         {
  1760.           str = attr_printf (strlen (unit->name) + sizeof ("*_cost_") + MAX_DIGITS,
  1761.                  "*%s_cost_%d", unit->name, op->num);
  1762.           make_internal_attr (str, issue_exp, 1);
  1763.         }
  1764.  
  1765.       /* Validate the condition.  */
  1766.       op->condexp = check_attr_test (op->condexp, 0);
  1767.     }
  1768.     }
  1769.  
  1770.   /* Compute the mask of function units used.  Initially, the unitsmask is
  1771.      zero.   Set up a conditional to compute each unit's contribution.  */
  1772.   unitsmask = make_numeric_value (0);
  1773.   newexp = rtx_alloc (IF_THEN_ELSE);
  1774.   XEXP (newexp, 2) = make_numeric_value (0);
  1775.  
  1776.   /* Merge each function unit into the unit mask attributes.  */
  1777.   for (unit = units; unit; unit = unit->next)
  1778.     {
  1779.       XEXP (newexp, 0) = unit->condexp;
  1780.       XEXP (newexp, 1) = make_numeric_value (1 << unit->num);
  1781.       unitsmask = operate_exp (OR_OP, unitsmask, newexp);
  1782.     }
  1783.  
  1784.   /* Simplify the unit mask expression, encode it, and make an attribute
  1785.      for the function_units_used function.  */
  1786.   unitsmask = simplify_by_exploding (unitsmask);
  1787.   unitsmask = encode_units_mask (unitsmask);
  1788.   make_internal_attr ("*function_units_used", unitsmask, 2);
  1789.  
  1790.   /* Create an array of ops for each unit.  Add an extra unit for the
  1791.      result_ready_cost function that has the ops of all other units.  */
  1792.   unit_ops = (struct function_unit_op ***)
  1793.     alloca ((num_units + 1) * sizeof (struct function_unit_op **));
  1794.   unit_num = (struct function_unit **)
  1795.     alloca ((num_units + 1) * sizeof (struct function_unit *));
  1796.  
  1797.   unit_num[num_units] = unit = (struct function_unit *)
  1798.     alloca (sizeof (struct function_unit));
  1799.   unit->num = num_units;
  1800.   unit->num_opclasses = 0;
  1801.  
  1802.   for (unit = units; unit; unit = unit->next)
  1803.     {
  1804.       unit_num[num_units]->num_opclasses += unit->num_opclasses;
  1805.       unit_num[unit->num] = unit;
  1806.       unit_ops[unit->num] = op_array = (struct function_unit_op **)
  1807.     alloca (unit->num_opclasses * sizeof (struct function_unit_op *));
  1808.  
  1809.       for (op = unit->ops; op; op = op->next)
  1810.     op_array[op->num] = op;
  1811.     }
  1812.  
  1813.   /* Compose the array of ops for the extra unit.  */
  1814.   unit_ops[num_units] = op_array = (struct function_unit_op **)
  1815.     alloca (unit_num[num_units]->num_opclasses
  1816.         * sizeof (struct function_unit_op *));
  1817.  
  1818.   for (unit = units, i = 0; unit; i += unit->num_opclasses, unit = unit->next)
  1819.     bcopy (unit_ops[unit->num], &op_array[i],
  1820.        unit->num_opclasses * sizeof (struct function_unit_op *));
  1821.  
  1822.   /* Compute the ready cost function for each unit by computing the
  1823.      condition for each non-default value.  */
  1824.   for (u = 0; u <= num_units; u++)
  1825.     {
  1826.       rtx orexp;
  1827.       int value;
  1828.  
  1829.       unit = unit_num[u];
  1830.       op_array = unit_ops[unit->num];
  1831.       num = unit->num_opclasses;
  1832.  
  1833.       /* Sort the array of ops into increasing ready cost order.  */
  1834.       for (i = 0; i < num; i++)
  1835.     for (j = num - 1; j > i; j--)
  1836.       if (op_array[j-1]->ready < op_array[j]->ready)
  1837.         {
  1838.           op = op_array[j];
  1839.           op_array[j] = op_array[j-1];
  1840.           op_array[j-1] = op;
  1841.         }
  1842.  
  1843.       /* Determine how many distinct non-default ready cost values there
  1844.      are.  We use a default ready cost value of 1.  */
  1845.       nvalues = 0; value = 1;
  1846.       for (i = num - 1; i >= 0; i--)
  1847.     if (op_array[i]->ready > value)
  1848.       {
  1849.         value = op_array[i]->ready;
  1850.         nvalues++;
  1851.       }
  1852.  
  1853.       if (nvalues == 0)
  1854.     readycost = make_numeric_value (1);
  1855.       else
  1856.     {
  1857.       /* Construct the ready cost expression as a COND of each value from
  1858.          the largest to the smallest.  */
  1859.       readycost = rtx_alloc (COND);
  1860.       XVEC (readycost, 0) = rtvec_alloc (nvalues * 2);
  1861.       XEXP (readycost, 1) = make_numeric_value (1);
  1862.  
  1863.       nvalues = 0; orexp = false_rtx; value = op_array[0]->ready;
  1864.       for (i = 0; i < num; i++)
  1865.         {
  1866.           op = op_array[i];
  1867.           if (op->ready <= 1)
  1868.         break;
  1869.           else if (op->ready == value)
  1870.         orexp = insert_right_side (IOR, orexp, op->condexp, -2);
  1871.           else
  1872.         {
  1873.           XVECEXP (readycost, 0, nvalues * 2) = orexp;
  1874.           XVECEXP (readycost, 0, nvalues * 2 + 1)
  1875.             = make_numeric_value (value);
  1876.           nvalues++;
  1877.           value = op->ready;
  1878.           orexp = op->condexp;
  1879.         }
  1880.         }
  1881.       XVECEXP (readycost, 0, nvalues * 2) = orexp;
  1882.       XVECEXP (readycost, 0, nvalues * 2 + 1) = make_numeric_value (value);
  1883.     }
  1884.  
  1885.       if (u < num_units)
  1886.     {
  1887.       rtx max_blockage = 0, min_blockage = 0;
  1888.  
  1889.       /* Simplify the readycost expression by only considering insns
  1890.          that use the unit.  */
  1891.       readycost = simplify_knowing (readycost, unit->condexp);
  1892.  
  1893.       /* Determine the blockage cost the executing insn (E) given
  1894.          the candidate insn (C).  This is the maximum of the issue
  1895.          delay, the pipeline delay, and the simultaneity constraint.
  1896.          Each function_unit_op represents the characteristics of the
  1897.          candidate insn, so in the expressions below, C is a known
  1898.          term and E is an unknown term.
  1899.  
  1900.          The issue delay function for C is op->issue_exp and is used to
  1901.          write the `<name>_unit_conflict_cost' function.  Symbolicly
  1902.          this is "ISSUE-DELAY (E,C)".
  1903.  
  1904.          The pipeline delay results form the FIFO constraint on the
  1905.          function unit and is "READY-COST (E) + 1 - READY-COST (C)".
  1906.  
  1907.          The simultaneity constraint is based on how long it takes to
  1908.          fill the unit given the minimum issue delay.  FILL-TIME is the
  1909.          constant "MIN (ISSUE-DELAY (*,*)) * (SIMULTANEITY - 1)", and
  1910.          the simultaneity constraint is "READY-COST (E) - FILL-TIME"
  1911.          if SIMULTANEITY is non-zero and zero otherwise.
  1912.  
  1913.          Thus, BLOCKAGE (E,C) when SIMULTANEITY is zero is
  1914.  
  1915.              MAX (ISSUE-DELAY (E,C),
  1916.               READY-COST (E) - (READY-COST (C) - 1))
  1917.  
  1918.          and otherwise
  1919.  
  1920.              MAX (ISSUE-DELAY (E,C),
  1921.               READY-COST (E) - (READY-COST (C) - 1),
  1922.               READY-COST (E) - FILL-TIME)
  1923.  
  1924.          The `<name>_unit_blockage' function is computed by determining
  1925.          this value for each candidate insn.  As these values are
  1926.          computed, we also compute the upper and lower bounds for
  1927.          BLOCKAGE (E,*).  These are combined to form the function
  1928.          `<name>_unit_blockage_range'.  Finally, the maximum blockage
  1929.          cost, MAX (BLOCKAGE (*,*)), is computed.  */
  1930.  
  1931.       for (op = unit->ops; op; op = op->next)
  1932.         {
  1933.           rtx blockage = readycost;
  1934.           int delay = op->ready - 1;
  1935.  
  1936.           if (unit->simultaneity != 0)
  1937.         delay = MIN (delay, ((unit->simultaneity - 1)
  1938.                      * unit->issue_delay.min));
  1939.  
  1940.           if (delay > 0)
  1941.         blockage = operate_exp (POS_MINUS_OP, blockage,
  1942.                     make_numeric_value (delay));
  1943.  
  1944.           blockage = operate_exp (MAX_OP, blockage, op->issue_exp);
  1945.           blockage = simplify_knowing (blockage, unit->condexp);
  1946.  
  1947.           /* Add this op's contribution to MAX (BLOCKAGE (E,*)) and
  1948.          MIN (BLOCKAGE (E,*)).  */
  1949.           if (max_blockage == 0)
  1950.         max_blockage = min_blockage = blockage;
  1951.           else
  1952.         {
  1953.           max_blockage
  1954.             = simplify_knowing (operate_exp (MAX_OP, max_blockage,
  1955.                              blockage),
  1956.                     unit->condexp);
  1957.           min_blockage
  1958.             = simplify_knowing (operate_exp (MIN_OP, min_blockage,
  1959.                              blockage),
  1960.                     unit->condexp);
  1961.         }
  1962.  
  1963.           /* Make an attribute for use in the blockage function.  */
  1964.           str = attr_printf (strlen (unit->name) + sizeof ("*_block_") + MAX_DIGITS,
  1965.                  "*%s_block_%d", unit->name, op->num);
  1966.           make_internal_attr (str, blockage, 1);
  1967.         }
  1968.  
  1969.       /* Record MAX (BLOCKAGE (*,*)).  */
  1970.       unit->max_blockage = max_attr_value (max_blockage);
  1971.  
  1972.       /* See if the upper and lower bounds of BLOCKAGE (E,*) are the
  1973.          same.  If so, the blockage function carries no additional
  1974.          information and is not written.  */
  1975.       newexp = operate_exp (EQ_OP, max_blockage, min_blockage);
  1976.       newexp = simplify_knowing (newexp, unit->condexp);
  1977.       unit->needs_blockage_function
  1978.         = (GET_CODE (newexp) != CONST_STRING
  1979.            || atoi (XSTR (newexp, 0)) != 1);
  1980.  
  1981.       /* If the all values of BLOCKAGE (E,C) have the same value,
  1982.          neither blockage function is written.  */      
  1983.       unit->needs_range_function
  1984.         = (unit->needs_blockage_function
  1985.            || GET_CODE (max_blockage) != CONST_STRING);
  1986.  
  1987.       if (unit->needs_range_function)
  1988.         {
  1989.           /* Compute the blockage range function and make an attribute
  1990.          for writing it's value.  */
  1991.           newexp = operate_exp (RANGE_OP, min_blockage, max_blockage);
  1992.           newexp = simplify_knowing (newexp, unit->condexp);
  1993.  
  1994.           str = attr_printf (strlen (unit->name) + sizeof ("*_unit_blockage_range"),
  1995.                  "*%s_unit_blockage_range", unit->name);
  1996.           make_internal_attr (str, newexp, 4);
  1997.         }
  1998.  
  1999.       str = attr_printf (strlen (unit->name) + sizeof ("*_unit_ready_cost"),
  2000.                  "*%s_unit_ready_cost", unit->name);
  2001.     }
  2002.       else
  2003.     str = "*result_ready_cost";
  2004.  
  2005.       /* Make an attribute for the ready_cost function.  Simplifying
  2006.      further with simplify_by_exploding doesn't win.  */
  2007.       make_internal_attr (str, readycost, 0);
  2008.     }
  2009.  
  2010.   /* For each unit that requires a conflict cost function, make an attribute
  2011.      that maps insns to the operation number.  */
  2012.   for (unit = units; unit; unit = unit->next)
  2013.     {
  2014.       rtx caseexp;
  2015.  
  2016.       if (! unit->needs_conflict_function
  2017.       && ! unit->needs_blockage_function)
  2018.     continue;
  2019.  
  2020.       caseexp = rtx_alloc (COND);
  2021.       XVEC (caseexp, 0) = rtvec_alloc ((unit->num_opclasses - 1) * 2);
  2022.  
  2023.       for (op = unit->ops; op; op = op->next)
  2024.     {
  2025.       /* Make our adjustment to the COND being computed.  If we are the
  2026.          last operation class, place our values into the default of the
  2027.          COND.  */
  2028.       if (op->num == unit->num_opclasses - 1)
  2029.         {
  2030.           XEXP (caseexp, 1) = make_numeric_value (op->num);
  2031.         }
  2032.       else
  2033.         {
  2034.           XVECEXP (caseexp, 0, op->num * 2) = op->condexp;
  2035.           XVECEXP (caseexp, 0, op->num * 2 + 1)
  2036.         = make_numeric_value (op->num);
  2037.         }
  2038.     }
  2039.  
  2040.       /* Simplifying caseexp with simplify_by_exploding doesn't win.  */
  2041.       str = attr_printf (strlen (unit->name) + sizeof ("*_cases"),
  2042.              "*%s_cases", unit->name);
  2043.       make_internal_attr (str, caseexp, 1);
  2044.     }
  2045. }
  2046.  
  2047. /* Simplify EXP given KNOWN_TRUE.  */
  2048.  
  2049. static rtx
  2050. simplify_knowing (exp, known_true)
  2051.      rtx exp, known_true;
  2052. {
  2053.   if (GET_CODE (exp) != CONST_STRING)
  2054.     {
  2055.       exp = attr_rtx (IF_THEN_ELSE, known_true, exp,
  2056.               make_numeric_value (max_attr_value (exp)));
  2057.       exp = simplify_by_exploding (exp);
  2058.     }
  2059.   return exp;
  2060. }
  2061.  
  2062. /* Translate the CONST_STRING expressions in X to change the encoding of
  2063.    value.  On input, the value is a bitmask with a one bit for each unit
  2064.    used; on output, the value is the unit number (zero based) if one
  2065.    and only one unit is used or the one's compliment of the bitmask.  */
  2066.  
  2067. static rtx
  2068. encode_units_mask (x)
  2069.      rtx x;
  2070. {
  2071.   register int i;
  2072.   register int j;
  2073.   register enum rtx_code code;
  2074.   register char *fmt;
  2075.  
  2076.   code = GET_CODE (x);
  2077.  
  2078.   switch (code)
  2079.     {
  2080.     case CONST_STRING:
  2081.       i = atoi (XSTR (x, 0));
  2082.       if (i < 0)
  2083.     abort (); /* The sign bit encodes a one's compliment mask.  */
  2084.       else if (i != 0 && i == (i & -i))
  2085.     /* Only one bit is set, so yield that unit number.  */
  2086.     for (j = 0; (i >>= 1) != 0; j++)
  2087.       ;
  2088.       else
  2089.     j = ~i;
  2090.       return attr_rtx (CONST_STRING, attr_printf (MAX_DIGITS, "%d", j));
  2091.  
  2092.     case REG:
  2093.     case QUEUED:
  2094.     case CONST_INT:
  2095.     case CONST_DOUBLE:
  2096.     case SYMBOL_REF:
  2097.     case CODE_LABEL:
  2098.     case PC:
  2099.     case CC0:
  2100.     case EQ_ATTR:
  2101.       return x;
  2102.     }
  2103.  
  2104.   /* Compare the elements.  If any pair of corresponding elements
  2105.      fail to match, return 0 for the whole things.  */
  2106.  
  2107.   fmt = GET_RTX_FORMAT (code);
  2108.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2109.     {
  2110.       switch (fmt[i])
  2111.     {
  2112.     case 'V':
  2113.     case 'E':
  2114.       for (j = 0; j < XVECLEN (x, i); j++)
  2115.         XVECEXP (x, i, j) = encode_units_mask (XVECEXP (x, i, j));
  2116.       break;
  2117.  
  2118.     case 'e':
  2119.       XEXP (x, i) = encode_units_mask (XEXP (x, i));
  2120.       break;
  2121.     }
  2122.     }
  2123.   return x;
  2124. }
  2125.  
  2126. /* Once all attributes and insns have been read and checked, we construct for
  2127.    each attribute value a list of all the insns that have that value for
  2128.    the attribute.  */
  2129.  
  2130. static void
  2131. fill_attr (attr)
  2132.      struct attr_desc *attr;
  2133. {
  2134.   struct attr_value *av;
  2135.   struct insn_ent *ie;
  2136.   struct insn_def *id;
  2137.   int i;
  2138.   rtx value;
  2139.  
  2140.   /* Don't fill constant attributes.  The value is independent of
  2141.      any particular insn.  */
  2142.   if (attr->is_const)
  2143.     return;
  2144.  
  2145.   for (id = defs; id; id = id->next)
  2146.     {
  2147.       /* If no value is specified for this insn for this attribute, use the
  2148.      default.  */
  2149.       value = NULL;
  2150.       if (XVEC (id->def, id->vec_idx))
  2151.     for (i = 0; i < XVECLEN (id->def, id->vec_idx); i++)
  2152.       if (! strcmp (XSTR (XEXP (XVECEXP (id->def, id->vec_idx, i), 0), 0), 
  2153.             attr->name))
  2154.         value = XEXP (XVECEXP (id->def, id->vec_idx, i), 1);
  2155.  
  2156.       if (value == NULL)
  2157.     av = attr->default_val;
  2158.       else
  2159.     av = get_attr_value (value, attr, id->insn_code);
  2160.  
  2161.       ie = (struct insn_ent *) oballoc (sizeof (struct insn_ent));
  2162.       ie->insn_code = id->insn_code;
  2163.       ie->insn_index = id->insn_code;
  2164.       insert_insn_ent (av, ie);
  2165.     }
  2166. }
  2167.  
  2168. /* Given an expression EXP, see if it is a COND or IF_THEN_ELSE that has a
  2169.    test that checks relative positions of insns (uses MATCH_DUP or PC).
  2170.    If so, replace it with what is obtained by passing the expression to
  2171.    ADDRESS_FN.  If not but it is a COND or IF_THEN_ELSE, call this routine
  2172.    recursively on each value (including the default value).  Otherwise,
  2173.    return the value returned by NO_ADDRESS_FN applied to EXP.  */
  2174.  
  2175. static rtx
  2176. substitute_address (exp, no_address_fn, address_fn)
  2177.      rtx exp;
  2178.      rtx (*no_address_fn) ();
  2179.      rtx (*address_fn) ();
  2180. {
  2181.   int i;
  2182.   rtx newexp;
  2183.  
  2184.   if (GET_CODE (exp) == COND)
  2185.     {
  2186.       /* See if any tests use addresses.  */
  2187.       address_used = 0;
  2188.       for (i = 0; i < XVECLEN (exp, 0); i += 2)
  2189.     walk_attr_value (XVECEXP (exp, 0, i));
  2190.  
  2191.       if (address_used)
  2192.     return (*address_fn) (exp);
  2193.  
  2194.       /* Make a new copy of this COND, replacing each element.  */
  2195.       newexp = rtx_alloc (COND);
  2196.       XVEC (newexp, 0) = rtvec_alloc (XVECLEN (exp, 0));
  2197.       for (i = 0; i < XVECLEN (exp, 0); i += 2)
  2198.     {
  2199.       XVECEXP (newexp, 0, i) = XVECEXP (exp, 0, i);
  2200.       XVECEXP (newexp, 0, i + 1)
  2201.         = substitute_address (XVECEXP (exp, 0, i + 1),
  2202.                   no_address_fn, address_fn);
  2203.     }
  2204.  
  2205.       XEXP (newexp, 1) = substitute_address (XEXP (exp, 1),
  2206.                          no_address_fn, address_fn);
  2207.  
  2208.       return newexp;
  2209.     }
  2210.  
  2211.   else if (GET_CODE (exp) == IF_THEN_ELSE)
  2212.     {
  2213.       address_used = 0;
  2214.       walk_attr_value (XEXP (exp, 0));
  2215.       if (address_used)
  2216.     return (*address_fn) (exp);
  2217.  
  2218.       return attr_rtx (IF_THEN_ELSE,
  2219.                substitute_address (XEXP (exp, 0),
  2220.                        no_address_fn, address_fn),
  2221.                substitute_address (XEXP (exp, 1),
  2222.                        no_address_fn, address_fn),
  2223.                substitute_address (XEXP (exp, 2),
  2224.                        no_address_fn, address_fn));
  2225.     }
  2226.  
  2227.   return (*no_address_fn) (exp);
  2228. }
  2229.  
  2230. /* Make new attributes from the `length' attribute.  The following are made,
  2231.    each corresponding to a function called from `shorten_branches' or
  2232.    `get_attr_length':
  2233.  
  2234.    *insn_default_length        This is the length of the insn to be returned
  2235.                 by `get_attr_length' before `shorten_branches'
  2236.                 has been called.  In each case where the length
  2237.                 depends on relative addresses, the largest
  2238.                 possible is used.  This routine is also used
  2239.                 to compute the initial size of the insn.
  2240.  
  2241.    *insn_variable_length_p    This returns 1 if the insn's length depends
  2242.                 on relative addresses, zero otherwise.
  2243.  
  2244.    *insn_current_length        This is only called when it is known that the
  2245.                 insn has a variable length and returns the
  2246.                 current length, based on relative addresses.
  2247.   */
  2248.  
  2249. #ifdef MPW
  2250. #pragma segment GENAT01
  2251. #endif
  2252.  
  2253. static void
  2254. make_length_attrs ()
  2255. {
  2256.   static char *new_names[] = {"*insn_default_length",
  2257.                   "*insn_variable_length_p",
  2258.                   "*insn_current_length"};
  2259.   static rtx (*no_address_fn[]) () = {identity_fn, zero_fn, zero_fn};
  2260.   static rtx (*address_fn[]) () = {max_fn, one_fn, identity_fn};
  2261.   int i;
  2262.   struct attr_desc *length_attr, *new_attr;
  2263.   struct attr_value *av, *new_av;
  2264.   struct insn_ent *ie, *new_ie;
  2265.  
  2266.   /* See if length attribute is defined.  If so, it must be numeric.  Make
  2267.      it special so we don't output anything for it.  */
  2268.   length_attr = find_attr ("length", 0);
  2269.   if (length_attr == 0)
  2270.     return;
  2271.  
  2272.   if (! length_attr->is_numeric)
  2273.     fatal ("length attribute must be numeric.");
  2274.  
  2275.   length_attr->is_const = 0;
  2276.   length_attr->is_special = 1;
  2277.  
  2278.   /* Make each new attribute, in turn.  */
  2279.   for (i = 0; i < sizeof new_names / sizeof new_names[0]; i++)
  2280.     {
  2281.       make_internal_attr (new_names[i],
  2282.               substitute_address (length_attr->default_val->value,
  2283.                           no_address_fn[i], address_fn[i]),
  2284.               0);
  2285.       new_attr = find_attr (new_names[i], 0);
  2286.       for (av = length_attr->first_value; av; av = av->next)
  2287.     for (ie = av->first_insn; ie; ie = ie->next)
  2288.       {
  2289.         new_av = get_attr_value (substitute_address (av->value,
  2290.                              no_address_fn[i],
  2291.                              address_fn[i]),
  2292.                      new_attr, ie->insn_code);
  2293.         new_ie = (struct insn_ent *) oballoc (sizeof (struct insn_ent));
  2294.         new_ie->insn_code = ie->insn_code;
  2295.         new_ie->insn_index = ie->insn_index;
  2296.         insert_insn_ent (new_av, new_ie);
  2297.       }
  2298.     }
  2299. }
  2300.  
  2301. /* Utility functions called from above routine.  */
  2302.  
  2303. static rtx
  2304. identity_fn (exp)
  2305.      rtx exp;
  2306. {
  2307.   return exp;
  2308. }
  2309.  
  2310. static rtx
  2311. zero_fn (exp)
  2312.      rtx exp;
  2313. {
  2314.   return make_numeric_value (0);
  2315. }
  2316.  
  2317. static rtx
  2318. one_fn (exp)
  2319.      rtx exp;
  2320. {
  2321.   return make_numeric_value (1);
  2322. }
  2323.  
  2324. static rtx
  2325. max_fn (exp)
  2326.      rtx exp;
  2327. {
  2328.   return make_numeric_value (max_attr_value (exp));
  2329. }
  2330.  
  2331. /* Take a COND expression and see if any of the conditions in it can be
  2332.    simplified.  If any are known true or known false for the particular insn
  2333.    code, the COND can be further simplified.
  2334.  
  2335.    Also call ourselves on any COND operations that are values of this COND.
  2336.  
  2337.    We do not modify EXP; rather, we make and return a new rtx.  */
  2338.  
  2339. static rtx
  2340. simplify_cond (exp, insn_code, insn_index)
  2341.      rtx exp;
  2342.      int insn_code, insn_index;
  2343. {
  2344.   int i, j;
  2345.   /* We store the desired contents here,
  2346.      then build a new expression if they don't match EXP.  */
  2347.   rtx defval = XEXP (exp, 1);
  2348.   rtx new_defval = XEXP (exp, 1);
  2349.  
  2350.   int len = XVECLEN (exp, 0);
  2351.   rtx *tests = (rtx *) alloca (len * sizeof (rtx));
  2352.   int allsame = 1;
  2353.   char *first_spacer;
  2354.  
  2355.   /* This lets us free all storage allocated below, if appropriate.  */
  2356.   first_spacer = (char *) obstack_finish (rtl_obstack);
  2357.  
  2358.   bcopy (&XVECEXP (exp, 0, 0), tests, len * sizeof (rtx));
  2359.  
  2360.   /* See if default value needs simplification.  */
  2361.   if (GET_CODE (defval) == COND)
  2362.     new_defval = simplify_cond (defval, insn_code, insn_index);
  2363.  
  2364.   /* Simplify the subexpressions, and see what tests we can get rid of.  */
  2365.  
  2366.   for (i = 0; i < len; i += 2)
  2367.     {
  2368.       rtx newtest, newval;
  2369.  
  2370.       /* Simplify this test.  */
  2371.       newtest = SIMPLIFY_TEST_EXP (tests[i], insn_code, insn_index);
  2372.       tests[i] = newtest;
  2373.  
  2374.       newval = tests[i + 1];
  2375.       /* See if this value may need simplification.  */
  2376.       if (GET_CODE (newval) == COND)
  2377.     newval = simplify_cond (newval, insn_code, insn_index);
  2378.  
  2379.       /* Look for ways to delete or combine this test.  */
  2380.       if (newtest == true_rtx)
  2381.     {
  2382.       /* If test is true, make this value the default
  2383.          and discard this + any following tests.  */
  2384.       len = i;
  2385.       defval = tests[i + 1];
  2386.       new_defval = newval;
  2387.     }
  2388.  
  2389.       else if (newtest == false_rtx)
  2390.     {
  2391.       /* If test is false, discard it and its value.  */
  2392.       for (j = i; j < len - 2; j++)
  2393.         tests[j] = tests[j + 2];
  2394.       len -= 2;
  2395.     }
  2396.  
  2397.       else if (i > 0 && attr_equal_p (newval, tests[i - 1]))
  2398.     {
  2399.       /* If this value and the value for the prev test are the same,
  2400.          merge the tests.  */
  2401.  
  2402.       tests[i - 2]
  2403.         = insert_right_side (IOR, tests[i - 2], newtest,
  2404.                  insn_code, insn_index);
  2405.  
  2406.       /* Delete this test/value.  */
  2407.       for (j = i; j < len - 2; j++)
  2408.         tests[j] = tests[j + 2];
  2409.       len -= 2;
  2410.     }
  2411.  
  2412.       else
  2413.     tests[i + 1] = newval;
  2414.     }
  2415.  
  2416.   /* If the last test in a COND has the same value
  2417.      as the default value, that test isn't needed.  */
  2418.  
  2419.   while (len > 0 && attr_equal_p (tests[len - 1], new_defval))
  2420.     len -= 2;
  2421.  
  2422.   /* See if we changed anything.  */
  2423.   if (len != XVECLEN (exp, 0) || new_defval != XEXP (exp, 1))
  2424.     allsame = 0;
  2425.   else
  2426.     for (i = 0; i < len; i++)
  2427.       if (! attr_equal_p (tests[i], XVECEXP (exp, 0, i)))
  2428.     {
  2429.       allsame = 0;
  2430.       break;
  2431.     }
  2432.  
  2433.   if (len == 0)
  2434.     {
  2435.       obstack_free (rtl_obstack, first_spacer);
  2436.       if (GET_CODE (defval) == COND)
  2437.     return simplify_cond (defval, insn_code, insn_index);
  2438.       return defval;
  2439.     }
  2440.   else if (allsame)
  2441.     {
  2442.       obstack_free (rtl_obstack, first_spacer);
  2443.       return exp;
  2444.     }
  2445.   else
  2446.     {
  2447.       rtx newexp = rtx_alloc (COND);
  2448.  
  2449.       XVEC (newexp, 0) = rtvec_alloc (len);
  2450.       bcopy (tests, &XVECEXP (newexp, 0, 0), len * sizeof (rtx));
  2451.       XEXP (newexp, 1) = new_defval;
  2452.       return newexp;
  2453.     }
  2454. }
  2455.  
  2456. /* Remove an insn entry from an attribute value.  */
  2457.  
  2458. static void
  2459. remove_insn_ent (av, ie)
  2460.      struct attr_value *av;
  2461.      struct insn_ent *ie;
  2462. {
  2463.   struct insn_ent *previe;
  2464.  
  2465.   if (av->first_insn == ie)
  2466.     av->first_insn = ie->next;
  2467.   else
  2468.     {
  2469.       for (previe = av->first_insn; previe->next != ie; previe = previe->next)
  2470.     ;
  2471.       previe->next = ie->next;
  2472.     }
  2473.  
  2474.   av->num_insns--;
  2475.   if (ie->insn_code == -1)
  2476.     av->has_asm_insn = 0;
  2477. }
  2478.  
  2479. /* Insert an insn entry in an attribute value list.  */
  2480.  
  2481. static void
  2482. insert_insn_ent (av, ie)
  2483.      struct attr_value *av;
  2484.      struct insn_ent *ie;
  2485. {
  2486.   ie->next = av->first_insn;
  2487.   av->first_insn = ie;
  2488.   av->num_insns++;
  2489.   if (ie->insn_code == -1)
  2490.     av->has_asm_insn = 1;
  2491. }
  2492.  
  2493. /* This is a utility routine to take an expression that is a tree of either
  2494.    AND or IOR expressions and insert a new term.  The new term will be
  2495.    inserted at the right side of the first node whose code does not match
  2496.    the root.  A new node will be created with the root's code.  Its left
  2497.    side will be the old right side and its right side will be the new
  2498.    term.
  2499.  
  2500.    If the `term' is itself a tree, all its leaves will be inserted.  */
  2501.  
  2502. static rtx
  2503. insert_right_side (code, exp, term, insn_code, insn_index)
  2504.      RTX_CODE code;
  2505.      rtx exp;
  2506.      rtx term;
  2507.      int insn_code, insn_index;
  2508. {
  2509.   rtx newexp;
  2510.  
  2511.   /* Avoid consing in some special cases.  */
  2512.   if (code == AND && term == true_rtx)
  2513.     return exp;
  2514.   if (code == AND && term == false_rtx)
  2515.     return false_rtx;
  2516.   if (code == AND && exp == true_rtx)
  2517.     return term;
  2518.   if (code == AND && exp == false_rtx)
  2519.     return false_rtx;
  2520.   if (code == IOR && term == true_rtx)
  2521.     return true_rtx;
  2522.   if (code == IOR && term == false_rtx)
  2523.     return exp;
  2524.   if (code == IOR && exp == true_rtx)
  2525.     return true_rtx;
  2526.   if (code == IOR && exp == false_rtx)
  2527.     return term;
  2528.   if (attr_equal_p (exp, term))
  2529.     return exp;
  2530.  
  2531.   if (GET_CODE (term) == code)
  2532.     {
  2533.       exp = insert_right_side (code, exp, XEXP (term, 0),
  2534.                    insn_code, insn_index);
  2535.       exp = insert_right_side (code, exp, XEXP (term, 1),
  2536.                    insn_code, insn_index);
  2537.  
  2538.       return exp;
  2539.     }
  2540.  
  2541.   if (GET_CODE (exp) == code)
  2542.     {
  2543.       rtx new = insert_right_side (code, XEXP (exp, 1),
  2544.                    term, insn_code, insn_index);
  2545.       if (new != XEXP (exp, 1))
  2546.     /* Make a copy of this expression and call recursively.  */
  2547.     newexp = attr_rtx (code, XEXP (exp, 0), new);
  2548.       else
  2549.     newexp = exp;
  2550.     }
  2551.   else
  2552.     {
  2553.       /* Insert the new term.  */
  2554.       newexp = attr_rtx (code, exp, term);
  2555.     }
  2556.  
  2557.   return SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  2558. }
  2559.  
  2560. /* If we have an expression which AND's a bunch of
  2561.     (not (eq_attrq "alternative" "n"))
  2562.    terms, we may have covered all or all but one of the possible alternatives.
  2563.    If so, we can optimize.  Similarly for IOR's of EQ_ATTR.
  2564.  
  2565.    This routine is passed an expression and either AND or IOR.  It returns a
  2566.    bitmask indicating which alternatives are present.
  2567.    ??? What does "present" mean?  */
  2568.  
  2569. static int
  2570. compute_alternative_mask (exp, code)
  2571.      rtx exp;
  2572.      RTX_CODE code;
  2573. {
  2574.   char *string;
  2575.   if (GET_CODE (exp) == code)
  2576.     return compute_alternative_mask (XEXP (exp, 0), code)
  2577.        | compute_alternative_mask (XEXP (exp, 1), code);
  2578.  
  2579.   else if (code == AND && GET_CODE (exp) == NOT
  2580.        && GET_CODE (XEXP (exp, 0)) == EQ_ATTR
  2581.        && XSTR (XEXP (exp, 0), 0) == alternative_name)
  2582.     string = XSTR (XEXP (exp, 0), 1);
  2583.  
  2584.   else if (code == IOR && GET_CODE (exp) == EQ_ATTR
  2585.        && XSTR (exp, 0) == alternative_name)
  2586.     string = XSTR (exp, 1);
  2587.  
  2588.   else
  2589.     return 0;
  2590.  
  2591.   if (string[1] == 0)
  2592.     return 1 << (string[0] - '0');
  2593.   return 1 << atoi (string);
  2594. }
  2595.  
  2596. /* Given I, a single-bit mask, return RTX to compare the `alternative'
  2597.    attribute with the value represented by that bit.  */
  2598.  
  2599. static rtx
  2600. make_alternative_compare (mask)
  2601.      int mask;
  2602. {
  2603.   rtx newexp;
  2604.   int i;
  2605.  
  2606.   /* Find the bit.  */
  2607.   for (i = 0; (mask & (1 << i)) == 0; i++)
  2608.     ;
  2609.  
  2610.   newexp = attr_rtx (EQ_ATTR, alternative_name, attr_numeral (i));
  2611.   RTX_UNCHANGING_P (newexp) = 1;
  2612.  
  2613.   return newexp;
  2614. }
  2615.  
  2616. /* If we are processing an (eq_attr "attr" "value") test, we find the value
  2617.    of "attr" for this insn code.  From that value, we can compute a test
  2618.    showing when the EQ_ATTR will be true.  This routine performs that
  2619.    computation.  If a test condition involves an address, we leave the EQ_ATTR
  2620.    intact because addresses are only valid for the `length' attribute.  */
  2621.  
  2622. /* ??? Kenner, document the meanings of the arguments!!!  */
  2623.  
  2624. static rtx
  2625. evaluate_eq_attr (exp, value, insn_code, insn_index)
  2626.      rtx exp;
  2627.      rtx value;
  2628.      int insn_code, insn_index;
  2629. {
  2630.   rtx orexp, andexp;
  2631.   rtx right;
  2632.   rtx newexp;
  2633.   int i;
  2634.  
  2635.   if (GET_CODE (value) == CONST_STRING)
  2636.     {
  2637.       if (! strcmp (XSTR (value, 0), XSTR (exp, 1)))
  2638.     newexp = true_rtx;
  2639.       else
  2640.     newexp = false_rtx;
  2641.     }
  2642.   else if (GET_CODE (value) == COND)
  2643.     {
  2644.       /* We construct an IOR of all the cases for which the requested attribute
  2645.      value is present.  Since we start with FALSE, if it is not present,
  2646.      FALSE will be returned.
  2647.  
  2648.      Each case is the AND of the NOT's of the previous conditions with the
  2649.      current condition; in the default case the current condition is TRUE. 
  2650.  
  2651.      For each possible COND value, call ourselves recursively.
  2652.  
  2653.      The extra TRUE and FALSE expressions will be eliminated by another
  2654.      call to the simplification routine. */
  2655.  
  2656.       orexp = false_rtx;
  2657.       andexp = true_rtx;
  2658.  
  2659.       if (current_alternative_string)
  2660.     clear_struct_flag (value);
  2661.  
  2662.       for (i = 0; i < XVECLEN (value, 0); i += 2)
  2663.     {
  2664.       rtx this = SIMPLIFY_TEST_EXP (XVECEXP (value, 0, i),
  2665.                     insn_code, insn_index);
  2666.  
  2667.       SIMPLIFY_ALTERNATIVE (this);
  2668.  
  2669.       right = insert_right_side (AND, andexp, this,
  2670.                      insn_code, insn_index);
  2671.       right = insert_right_side (AND, right,
  2672.             evaluate_eq_attr (exp, XVECEXP (value, 0, i + 1),
  2673.                        insn_code, insn_index),
  2674.                      insn_code, insn_index);
  2675.       orexp = insert_right_side (IOR, orexp, right,
  2676.                      insn_code, insn_index);
  2677.  
  2678.       /* Add this condition into the AND expression.  */
  2679.       newexp = attr_rtx (NOT, this);
  2680.       andexp = insert_right_side (AND, andexp, newexp,
  2681.                       insn_code, insn_index);
  2682.     }
  2683.  
  2684.       /* Handle the default case.  */
  2685.       right = insert_right_side (AND, andexp,
  2686.                  evaluate_eq_attr (exp, XEXP (value, 1),
  2687.                             insn_code, insn_index),
  2688.                  insn_code, insn_index);
  2689.       newexp = insert_right_side (IOR, orexp, right, insn_code, insn_index);
  2690.     }
  2691.   else
  2692.     abort ();
  2693.  
  2694.   /* If uses an address, must return original expression.  But set the
  2695.      RTX_UNCHANGING_P bit so we don't try to simplify it again.  */
  2696.  
  2697.   address_used = 0;
  2698.   walk_attr_value (newexp);
  2699.  
  2700.   if (address_used)
  2701.     {
  2702.       /* This had `&& current_alternative_string', which seems to be wrong.  */
  2703.       if (! RTX_UNCHANGING_P (exp))
  2704.     return copy_rtx_unchanging (exp);
  2705.       return exp;
  2706.     }
  2707.   else
  2708.     return newexp;
  2709. }
  2710.  
  2711. /* This routine is called when an AND of a term with a tree of AND's is
  2712.    encountered.  If the term or its complement is present in the tree, it
  2713.    can be replaced with TRUE or FALSE, respectively.
  2714.  
  2715.    Note that (eq_attr "att" "v1") and (eq_attr "att" "v2") cannot both
  2716.    be true and hence are complementary.  
  2717.  
  2718.    There is one special case:  If we see
  2719.     (and (not (eq_attr "att" "v1"))
  2720.          (eq_attr "att" "v2"))
  2721.    this can be replaced by (eq_attr "att" "v2").  To do this we need to
  2722.    replace the term, not anything in the AND tree.  So we pass a pointer to
  2723.    the term.  */
  2724.  
  2725. static rtx
  2726. simplify_and_tree (exp, pterm, insn_code, insn_index)
  2727.      rtx exp;
  2728.      rtx *pterm;
  2729.      int insn_code, insn_index;
  2730. {
  2731.   rtx left, right;
  2732.   rtx newexp;
  2733.   rtx temp;
  2734.   int left_eliminates_term, right_eliminates_term;
  2735.  
  2736.   if (GET_CODE (exp) == AND)
  2737.     {
  2738.       left = simplify_and_tree (XEXP (exp, 0), pterm,  insn_code, insn_index);
  2739.       right = simplify_and_tree (XEXP (exp, 1), pterm, insn_code, insn_index);
  2740.       if (left != XEXP (exp, 0) || right != XEXP (exp, 1))
  2741.     {
  2742.       newexp = attr_rtx (GET_CODE (exp), left, right);
  2743.  
  2744.       exp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  2745.     }
  2746.     }
  2747.  
  2748.   else if (GET_CODE (exp) == IOR)
  2749.     {
  2750.       /* For the IOR case, we do the same as above, except that we can
  2751.          only eliminate `term' if both sides of the IOR would do so.  */
  2752.       temp = *pterm;
  2753.       left = simplify_and_tree (XEXP (exp, 0), &temp,  insn_code, insn_index);
  2754.       left_eliminates_term = (temp == true_rtx);
  2755.  
  2756.       temp = *pterm;
  2757.       right = simplify_and_tree (XEXP (exp, 1), &temp, insn_code, insn_index);
  2758.       right_eliminates_term = (temp == true_rtx);
  2759.  
  2760.       if (left_eliminates_term && right_eliminates_term)
  2761.     *pterm = true_rtx;
  2762.  
  2763.       if (left != XEXP (exp, 0) || right != XEXP (exp, 1))
  2764.     {
  2765.       newexp = attr_rtx (GET_CODE (exp), left, right);
  2766.  
  2767.       exp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  2768.     }
  2769.     }
  2770.  
  2771.   /* Check for simplifications.  Do some extra checking here since this
  2772.      routine is called so many times.  */
  2773.  
  2774.   if (exp == *pterm)
  2775.     return true_rtx;
  2776.  
  2777.   else if (GET_CODE (exp) == NOT && XEXP (exp, 0) == *pterm)
  2778.     return false_rtx;
  2779.  
  2780.   else if (GET_CODE (*pterm) == NOT && exp == XEXP (*pterm, 0))
  2781.     return false_rtx;
  2782.  
  2783.   else if (GET_CODE (exp) == EQ_ATTR && GET_CODE (*pterm) == EQ_ATTR)
  2784.     {
  2785.       if (XSTR (exp, 0) != XSTR (*pterm, 0))
  2786.     return exp;
  2787.  
  2788.       if (! strcmp (XSTR (exp, 1), XSTR (*pterm, 1)))
  2789.     return true_rtx;
  2790.       else
  2791.     return false_rtx;
  2792.     }
  2793.  
  2794.   else if (GET_CODE (*pterm) == EQ_ATTR && GET_CODE (exp) == NOT
  2795.        && GET_CODE (XEXP (exp, 0)) == EQ_ATTR)
  2796.     {
  2797.       if (XSTR (*pterm, 0) != XSTR (XEXP (exp, 0), 0))
  2798.     return exp;
  2799.  
  2800.       if (! strcmp (XSTR (*pterm, 1), XSTR (XEXP (exp, 0), 1)))
  2801.     return false_rtx;
  2802.       else
  2803.     return true_rtx;
  2804.     }
  2805.  
  2806.   else if (GET_CODE (exp) == EQ_ATTR && GET_CODE (*pterm) == NOT
  2807.        && GET_CODE (XEXP (*pterm, 0)) == EQ_ATTR)
  2808.     {
  2809.       if (XSTR (exp, 0) != XSTR (XEXP (*pterm, 0), 0))
  2810.     return exp;
  2811.  
  2812.       if (! strcmp (XSTR (exp, 1), XSTR (XEXP (*pterm, 0), 1)))
  2813.     return false_rtx;
  2814.       else
  2815.     *pterm = true_rtx;
  2816.     }
  2817.  
  2818.   else if (GET_CODE (exp) == NOT && GET_CODE (*pterm) == NOT)
  2819.     {
  2820.       if (attr_equal_p (XEXP (exp, 0), XEXP (*pterm, 0)))
  2821.     return true_rtx;
  2822.     }
  2823.  
  2824.   else if (GET_CODE (exp) == NOT)
  2825.     {
  2826.       if (attr_equal_p (XEXP (exp, 0), *pterm))
  2827.     return false_rtx;
  2828.     }
  2829.  
  2830.   else if (GET_CODE (*pterm) == NOT)
  2831.     {
  2832.       if (attr_equal_p (XEXP (*pterm, 0), exp))
  2833.     return false_rtx;
  2834.     }
  2835.  
  2836.   else if (attr_equal_p (exp, *pterm))
  2837.     return true_rtx;
  2838.  
  2839.   return exp;
  2840. }
  2841.  
  2842. /* Similar to `simplify_and_tree', but for IOR trees.  */
  2843.  
  2844. static rtx
  2845. simplify_or_tree (exp, pterm, insn_code, insn_index)
  2846.      rtx exp;
  2847.      rtx *pterm;
  2848.      int insn_code, insn_index;
  2849. {
  2850.   rtx left, right;
  2851.   rtx newexp;
  2852.   rtx temp;
  2853.   int left_eliminates_term, right_eliminates_term;
  2854.  
  2855.   if (GET_CODE (exp) == IOR)
  2856.     {
  2857.       left = simplify_or_tree (XEXP (exp, 0), pterm,  insn_code, insn_index);
  2858.       right = simplify_or_tree (XEXP (exp, 1), pterm, insn_code, insn_index);
  2859.       if (left != XEXP (exp, 0) || right != XEXP (exp, 1))
  2860.     {
  2861.       newexp = attr_rtx (GET_CODE (exp), left, right);
  2862.  
  2863.       exp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  2864.     }
  2865.     }
  2866.  
  2867.   else if (GET_CODE (exp) == AND)
  2868.     {
  2869.       /* For the AND case, we do the same as above, except that we can
  2870.          only eliminate `term' if both sides of the AND would do so.  */
  2871.       temp = *pterm;
  2872.       left = simplify_or_tree (XEXP (exp, 0), &temp,  insn_code, insn_index);
  2873.       left_eliminates_term = (temp == false_rtx);
  2874.  
  2875.       temp = *pterm;
  2876.       right = simplify_or_tree (XEXP (exp, 1), &temp, insn_code, insn_index);
  2877.       right_eliminates_term = (temp == false_rtx);
  2878.  
  2879.       if (left_eliminates_term && right_eliminates_term)
  2880.     *pterm = false_rtx;
  2881.  
  2882.       if (left != XEXP (exp, 0) || right != XEXP (exp, 1))
  2883.     {
  2884.       newexp = attr_rtx (GET_CODE (exp), left, right);
  2885.  
  2886.       exp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  2887.     }
  2888.     }
  2889.  
  2890.   if (attr_equal_p (exp, *pterm))
  2891.     return false_rtx;
  2892.  
  2893.   else if (GET_CODE (exp) == NOT && attr_equal_p (XEXP (exp, 0), *pterm))
  2894.     return true_rtx;
  2895.  
  2896.   else if (GET_CODE (*pterm) == NOT && attr_equal_p (XEXP (*pterm, 0), exp))
  2897.     return true_rtx;
  2898.  
  2899.   else if (GET_CODE (*pterm) == EQ_ATTR && GET_CODE (exp) == NOT
  2900.        && GET_CODE (XEXP (exp, 0)) == EQ_ATTR
  2901.        && XSTR (*pterm, 0) == XSTR (XEXP (exp, 0), 0))
  2902.     *pterm = false_rtx;
  2903.  
  2904.   else if (GET_CODE (exp) == EQ_ATTR && GET_CODE (*pterm) == NOT
  2905.        && GET_CODE (XEXP (*pterm, 0)) == EQ_ATTR
  2906.        && XSTR (exp, 0) == XSTR (XEXP (*pterm, 0), 0))
  2907.     return false_rtx;
  2908.  
  2909.   return exp;
  2910. }
  2911.  
  2912. /* Given an expression, see if it can be simplified for a particular insn
  2913.    code based on the values of other attributes being tested.  This can
  2914.    eliminate nested get_attr_... calls.
  2915.  
  2916.    Note that if an endless recursion is specified in the patterns, the 
  2917.    optimization will loop.  However, it will do so in precisely the cases where
  2918.    an infinite recursion loop could occur during compilation.  It's better that
  2919.    it occurs here!  */
  2920.  
  2921. static rtx
  2922. simplify_test_exp (exp, insn_code, insn_index)
  2923.      rtx exp;
  2924.      int insn_code, insn_index;
  2925. {
  2926.   rtx left, right;
  2927.   struct attr_desc *attr;
  2928.   struct attr_value *av;
  2929.   struct insn_ent *ie;
  2930.   int i;
  2931.   rtx newexp = exp;
  2932.   char *spacer = (char *) obstack_finish (rtl_obstack);
  2933.  
  2934.   static rtx loser = 0;
  2935.   static int count = 0;
  2936.   static stopcount = 0;
  2937.  
  2938.   if (exp == loser)
  2939.     do_nothing ();
  2940.   count++;
  2941.   if (count == stopcount)
  2942.     do_nothing ();
  2943.  
  2944.   /* Don't re-simplify something we already simplified.  */
  2945.   if (RTX_UNCHANGING_P (exp) || MEM_IN_STRUCT_P (exp))
  2946.     return exp;
  2947.  
  2948.   switch (GET_CODE (exp))
  2949.     {
  2950.     case AND:
  2951.       left = SIMPLIFY_TEST_EXP (XEXP (exp, 0), insn_code, insn_index);
  2952.       SIMPLIFY_ALTERNATIVE (left);
  2953.       if (left == false_rtx)
  2954.     {
  2955.       obstack_free (rtl_obstack, spacer);
  2956.       return false_rtx;
  2957.     }
  2958.       right = SIMPLIFY_TEST_EXP (XEXP (exp, 1), insn_code, insn_index);
  2959.       SIMPLIFY_ALTERNATIVE (right);
  2960.       if (left == false_rtx)
  2961.     {
  2962.       obstack_free (rtl_obstack, spacer);
  2963.       return false_rtx;
  2964.     }
  2965.  
  2966.       /* If either side is an IOR and we have (eq_attr "alternative" ..")
  2967.      present on both sides, apply the distributive law since this will
  2968.      yield simplifications.  */
  2969.       if ((GET_CODE (left) == IOR || GET_CODE (right) == IOR)
  2970.       && compute_alternative_mask (left, IOR)
  2971.       && compute_alternative_mask (right, IOR))
  2972.     {
  2973.       if (GET_CODE (left) == IOR)
  2974.         {
  2975.           rtx tem = left;
  2976.           left = right;
  2977.           right = tem;
  2978.         }
  2979.  
  2980.       newexp = attr_rtx (IOR,
  2981.                  attr_rtx (AND, left, XEXP (right, 0)),
  2982.                  attr_rtx (AND, left, XEXP (right, 1)));
  2983.  
  2984.       return SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  2985.     }
  2986.  
  2987.       /* Try with the term on both sides.  */
  2988.       right = simplify_and_tree (right, &left, insn_code, insn_index);
  2989.       if (left == XEXP (exp, 0) && right == XEXP (exp, 1))
  2990.     left = simplify_and_tree (left, &right, insn_code, insn_index);
  2991.  
  2992.       if (left == false_rtx || right == false_rtx)
  2993.     {
  2994.       obstack_free (rtl_obstack, spacer);
  2995.       return false_rtx;
  2996.     }
  2997.       else if (left == true_rtx)
  2998.     {
  2999.       return right;
  3000.     }
  3001.       else if (right == true_rtx)
  3002.     {
  3003.       return left;
  3004.     }
  3005.       /* See if all or all but one of the insn's alternatives are specified
  3006.      in this tree.  Optimize if so.  */
  3007.  
  3008.       else if (insn_code >= 0
  3009.            && (GET_CODE (left) == AND
  3010.            || (GET_CODE (left) == NOT
  3011.                && GET_CODE (XEXP (left, 0)) == EQ_ATTR
  3012.                && XSTR (XEXP (left, 0), 0) == alternative_name)
  3013.            || GET_CODE (right) == AND
  3014.            || (GET_CODE (right) == NOT
  3015.                && GET_CODE (XEXP (right, 0)) == EQ_ATTR
  3016.                && XSTR (XEXP (right, 0), 0) == alternative_name)))
  3017.     {
  3018.       i = compute_alternative_mask (exp, AND);
  3019.       if (i & ~insn_alternatives[insn_code])
  3020.         fatal ("Illegal alternative specified for pattern number %d",
  3021.            insn_index);
  3022.  
  3023.       /* If all alternatives are excluded, this is false. */
  3024.       i ^= insn_alternatives[insn_code];
  3025.       if (i == 0)
  3026.         return false_rtx;
  3027.       else if ((i & (i - 1)) == 0 && insn_alternatives[insn_code] > 1)
  3028.         {
  3029.           /* If just one excluded, AND a comparison with that one to the
  3030.          front of the tree.  The others will be eliminated by
  3031.          optimization.  We do not want to do this if the insn has one
  3032.          alternative and we have tested none of them!  */
  3033.           left = make_alternative_compare (i);
  3034.           right = simplify_and_tree (exp, &left, insn_code, insn_index);
  3035.           newexp = attr_rtx (AND, left, right);
  3036.  
  3037.           return SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  3038.         }
  3039.     }
  3040.  
  3041.       if (left != XEXP (exp, 0) || right != XEXP (exp, 1))
  3042.     {
  3043.       newexp = attr_rtx (AND, left, right);
  3044.       return SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  3045.     }
  3046.       break;
  3047.  
  3048.     case IOR:
  3049.       left = SIMPLIFY_TEST_EXP (XEXP (exp, 0), insn_code, insn_index);
  3050.       SIMPLIFY_ALTERNATIVE (left);
  3051.       if (left == true_rtx)
  3052.     {
  3053.       obstack_free (rtl_obstack, spacer);
  3054.       return true_rtx;
  3055.     }
  3056.       right = SIMPLIFY_TEST_EXP (XEXP (exp, 1), insn_code, insn_index);
  3057.       SIMPLIFY_ALTERNATIVE (right);
  3058.       if (right == true_rtx)
  3059.     {
  3060.       obstack_free (rtl_obstack, spacer);
  3061.       return true_rtx;
  3062.     }
  3063.  
  3064.       right = simplify_or_tree (right, &left, insn_code, insn_index);
  3065.       if (left == XEXP (exp, 0) && right == XEXP (exp, 1))
  3066.     left = simplify_or_tree (left, &right, insn_code, insn_index);
  3067.  
  3068.       if (right == true_rtx || left == true_rtx)
  3069.     {
  3070.       obstack_free (rtl_obstack, spacer);
  3071.       return true_rtx;
  3072.     }
  3073.       else if (left == false_rtx)
  3074.     {
  3075.       return right;
  3076.     }
  3077.       else if (right == false_rtx)
  3078.     {
  3079.       return left;
  3080.     }
  3081.  
  3082.       /* Test for simple cases where the distributive law is useful.  I.e.,
  3083.         convert (ior (and (x) (y))
  3084.              (and (x) (z)))
  3085.         to      (and (x)
  3086.              (ior (y) (z)))
  3087.        */
  3088.  
  3089.       else if (GET_CODE (left) == AND && GET_CODE (right) == AND
  3090.       && attr_equal_p (XEXP (left, 0), XEXP (right, 0)))
  3091.     {
  3092.       newexp = attr_rtx (IOR, XEXP (left, 1), XEXP (right, 1));
  3093.  
  3094.       left = XEXP (left, 0);
  3095.       right = newexp;
  3096.       newexp = attr_rtx (AND, left, right);
  3097.       return SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  3098.     }
  3099.  
  3100.       /* See if all or all but one of the insn's alternatives are specified
  3101.      in this tree.  Optimize if so.  */
  3102.  
  3103.       else if (insn_code >= 0
  3104.       && (GET_CODE (left) == IOR
  3105.           || (GET_CODE (left) == EQ_ATTR
  3106.           && XSTR (left, 0) == alternative_name)
  3107.           || GET_CODE (right) == IOR
  3108.           || (GET_CODE (right) == EQ_ATTR
  3109.           && XSTR (right, 0) == alternative_name)))
  3110.     {
  3111.       i = compute_alternative_mask (exp, IOR);
  3112.       if (i & ~insn_alternatives[insn_code])
  3113.         fatal ("Illegal alternative specified for pattern number %d",
  3114.            insn_index);
  3115.  
  3116.       /* If all alternatives are included, this is true. */
  3117.       i ^= insn_alternatives[insn_code];
  3118.       if (i == 0)
  3119.         return true_rtx;
  3120.       else if ((i & (i - 1)) == 0 && insn_alternatives[insn_code] > 1)
  3121.         {
  3122.           /* If just one excluded, IOR a comparison with that one to the
  3123.          front of the tree.  The others will be eliminated by
  3124.          optimization.  We do not want to do this if the insn has one
  3125.          alternative and we have tested none of them!  */
  3126.           left = make_alternative_compare (i);
  3127.           right = simplify_and_tree (exp, &left, insn_code, insn_index);
  3128.           newexp = attr_rtx (IOR, attr_rtx (NOT, left), right);
  3129.  
  3130.           return SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  3131.         }
  3132.     }
  3133.  
  3134.       if (left != XEXP (exp, 0) || right != XEXP (exp, 1))
  3135.     {
  3136.       newexp = attr_rtx (IOR, left, right);
  3137.       return SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  3138.     }
  3139.       break;
  3140.  
  3141.     case NOT:
  3142.       if (GET_CODE (XEXP (exp, 0)) == NOT)
  3143.     {
  3144.       left = SIMPLIFY_TEST_EXP (XEXP (XEXP (exp, 0), 0),
  3145.                     insn_code, insn_index);
  3146.       SIMPLIFY_ALTERNATIVE (left);
  3147.       return left;
  3148.     }
  3149.  
  3150.       left = SIMPLIFY_TEST_EXP (XEXP (exp, 0), insn_code, insn_index);
  3151.       SIMPLIFY_ALTERNATIVE (left);
  3152.       if (GET_CODE (left) == NOT)
  3153.     return XEXP (left, 0);
  3154.  
  3155.       if (left == false_rtx)
  3156.     {
  3157.       obstack_free (rtl_obstack, spacer);
  3158.       return true_rtx;
  3159.     }
  3160.       else if (left == true_rtx)
  3161.     {
  3162.       obstack_free (rtl_obstack, spacer);
  3163.       return false_rtx;
  3164.     }
  3165.  
  3166.       /* Try to apply De`Morgan's laws.  */
  3167.       else if (GET_CODE (left) == IOR)
  3168.     {
  3169.       newexp = attr_rtx (AND,
  3170.                  attr_rtx (NOT, XEXP (left, 0)),
  3171.                  attr_rtx (NOT, XEXP (left, 1)));
  3172.  
  3173.       newexp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  3174.     }
  3175.       else if (GET_CODE (left) == AND)
  3176.     {
  3177.       newexp = attr_rtx (IOR,
  3178.                  attr_rtx (NOT, XEXP (left, 0)),
  3179.                  attr_rtx (NOT, XEXP (left, 1)));
  3180.  
  3181.       newexp = SIMPLIFY_TEST_EXP (newexp, insn_code, insn_index);
  3182.     }
  3183.       else if (left != XEXP (exp, 0))
  3184.     {
  3185.       newexp = attr_rtx (NOT, left);
  3186.     }
  3187.       break;
  3188.  
  3189.     case EQ_ATTR:
  3190.       if (current_alternative_string && XSTR (exp, 0) == alternative_name)
  3191.     return (XSTR (exp, 1) == current_alternative_string
  3192.         ? true_rtx : false_rtx);
  3193.     
  3194.       /* Look at the value for this insn code in the specified attribute.
  3195.      We normally can replace this comparison with the condition that
  3196.      would give this insn the values being tested for.   */
  3197.       if (XSTR (exp, 0) != alternative_name
  3198.       && (attr = find_attr (XSTR (exp, 0), 0)) != NULL)
  3199.     for (av = attr->first_value; av; av = av->next)
  3200.       for (ie = av->first_insn; ie; ie = ie->next)
  3201.         if (ie->insn_code == insn_code)
  3202.           return evaluate_eq_attr (exp, av->value, insn_code, insn_index);
  3203.     }
  3204.  
  3205.   /* We have already simplified this expression.  Simplifying it again
  3206.      won't buy anything unless we weren't given a valid insn code
  3207.      to process (i.e., we are canonicalizing something.).  */
  3208.   if (insn_code != -2 /* Seems wrong: && current_alternative_string.  */
  3209.       && ! RTX_UNCHANGING_P (newexp))
  3210.     return copy_rtx_unchanging (newexp);
  3211.  
  3212.   return newexp;
  3213. }
  3214.  
  3215. do_nothing ()
  3216. {}
  3217.  
  3218. /* Optimize the attribute lists by seeing if we can determine conditional
  3219.    values from the known values of other attributes.  This will save subroutine
  3220.    calls during the compilation.  */
  3221.  
  3222. static void
  3223. optimize_attrs ()
  3224. {
  3225.   struct attr_desc *attr;
  3226.   struct attr_value *av;
  3227.   struct insn_ent *ie;
  3228.   rtx newexp;
  3229.   int something_changed = 1;
  3230.   int i;
  3231.   struct attr_value_list { struct attr_value *av;
  3232.                struct insn_ent *ie;
  3233.                struct attr_desc * attr;
  3234.                struct attr_value_list *next; };
  3235.   struct attr_value_list **insn_code_values;
  3236.   struct attr_value_list *iv;
  3237.  
  3238.   /* For each insn code, make a list of all the insn_ent's for it,
  3239.      for all values for all attributes.  */
  3240.  
  3241.   /* Make 2 extra elements, for "code" values -2 and -1.  */
  3242.   insn_code_values
  3243.     = (struct attr_value_list **) alloca ((insn_code_number + 2)
  3244.                       * sizeof (struct attr_value_list *));
  3245.   bzero (insn_code_values,
  3246.      (insn_code_number + 2) * sizeof (struct attr_value_list *));
  3247.   /* Offset the table address so we can index by -2 or -1.  */
  3248.   insn_code_values += 2;
  3249.  
  3250.   for (i = 0; i < MAX_ATTRS_INDEX; i++)
  3251.     for (attr = attrs[i]; attr; attr = attr->next)
  3252.       for (av = attr->first_value; av; av = av->next)
  3253.     for (ie = av->first_insn; ie; ie = ie->next)
  3254.       {
  3255.         iv = ((struct attr_value_list *)
  3256.           alloca (sizeof (struct attr_value_list)));
  3257.         iv->attr = attr;
  3258.         iv->av = av;
  3259.         iv->ie = ie;
  3260.         iv->next = insn_code_values[ie->insn_code];
  3261.         insn_code_values[ie->insn_code] = iv;
  3262.       }
  3263.  
  3264.   /* Process one insn code at a time.  */
  3265.   for (i = -2; i < insn_code_number; i++)
  3266.     {
  3267.       /* Clear the MEM_IN_STRUCT_P flag everywhere relevant.
  3268.      We use it to mean "already simplified for this insn".  */
  3269.       for (iv = insn_code_values[i]; iv; iv = iv->next)
  3270.     clear_struct_flag (iv->av->value);
  3271.  
  3272.       /* Loop until nothing changes for one iteration.  */
  3273.       something_changed = 1;
  3274.       while (something_changed)
  3275.     {
  3276.       something_changed = 0;
  3277.       for (iv = insn_code_values[i]; iv; iv = iv->next)
  3278.         {
  3279.           struct obstack *old = rtl_obstack;
  3280.           char *spacer = (char *) obstack_finish (temp_obstack);
  3281.  
  3282.           attr = iv->attr;
  3283.           av = iv->av;
  3284.           ie = iv->ie;
  3285.           if (GET_CODE (av->value) != COND)
  3286.         continue;
  3287.  
  3288.           rtl_obstack = temp_obstack;
  3289. #if 0 /* This was intended as a speed up, but it was slower.  */
  3290.           if (insn_n_alternatives[ie->insn_code] > 6
  3291.           && count_sub_rtxs (av->value, 200) >= 200)
  3292.         newexp = simplify_by_alternatives (av->value, ie->insn_code,
  3293.                            ie->insn_index);
  3294.           else
  3295. #endif
  3296.         newexp = simplify_cond (av->value, ie->insn_code,
  3297.                     ie->insn_index);
  3298.  
  3299.           rtl_obstack = old;
  3300.           if (newexp != av->value)
  3301.         {
  3302.           newexp = attr_copy_rtx (newexp);
  3303.           remove_insn_ent (av, ie);
  3304.           av = get_attr_value (newexp, attr, ie->insn_code);
  3305.           iv->av = av;
  3306.           insert_insn_ent (av, ie);
  3307.           something_changed = 1;
  3308.         }
  3309.           obstack_free (temp_obstack, spacer);
  3310.         }
  3311.     }
  3312.     }
  3313. }
  3314.  
  3315. #if 0
  3316. static rtx
  3317. simplify_by_alternatives (exp, insn_code, insn_index)
  3318.      rtx exp;
  3319.      int insn_code, insn_index;
  3320. {
  3321.   int i;
  3322.   int len = insn_n_alternatives[insn_code];
  3323.   rtx newexp = rtx_alloc (COND);
  3324.   rtx ultimate;
  3325.  
  3326.  
  3327.   XVEC (newexp, 0) = rtvec_alloc (len * 2);
  3328.  
  3329.   /* It will not matter what value we use as the default value
  3330.      of the new COND, since that default will never be used.
  3331.      Choose something of the right type.  */
  3332.   for (ultimate = exp; GET_CODE (ultimate) == COND;)
  3333.     ultimate = XEXP (ultimate, 1);
  3334.   XEXP (newexp, 1) = ultimate;
  3335.  
  3336.   for (i = 0; i < insn_n_alternatives[insn_code]; i++)
  3337.     {
  3338.       current_alternative_string = attr_numeral (i);
  3339.       XVECEXP (newexp, 0, i * 2) = make_alternative_compare (1 << i);
  3340.       XVECEXP (newexp, 0, i * 2 + 1)
  3341.     = simplify_cond (exp, insn_code, insn_index);
  3342.     }
  3343.  
  3344.   current_alternative_string = 0;
  3345.   return simplify_cond (newexp, insn_code, insn_index);
  3346. }
  3347. #endif
  3348.  
  3349. /* An expression where all the unknown terms are EQ_ATTR tests can be
  3350.    rearranged into a COND provided we can enumerate all possible
  3351.    combinations of the unknown values.  The set of combinations become the
  3352.    tests of the COND; the value of the expression given that combination is
  3353.    computed and becomes the corresponding value.  To do this, we must be
  3354.    able to enumerate all values for each attribute used in the expression
  3355.    (currently, we give up if we find a numeric attribute).
  3356.    
  3357.    If the set of EQ_ATTR tests used in an expression tests the value of N
  3358.    different attributes, the list of all possible combinations can be made
  3359.    by walking the N-dimensional attribute space defined by those
  3360.    attributes.  We record each of these as a struct dimension.
  3361.  
  3362.    The algorithm relies on sharing EQ_ATTR nodes: if two nodes in an
  3363.    expression are the same, the will also have the same address.  We find
  3364.    all the EQ_ATTR nodes by marking them MEM_VOLATILE_P.  This bit later
  3365.    represents the value of an EQ_ATTR node, so once all nodes are marked,
  3366.    they are also given an initial value of FALSE.
  3367.  
  3368.    We then separate the set of EQ_ATTR nodes into dimensions for each
  3369.    attribute and put them on the VALUES list.  Terms are added as needed by
  3370.    `add_values_to_cover' so that all possible values of the attribute are
  3371.    tested.
  3372.  
  3373.    Each dimension also has a current value.  This is the node that is
  3374.    currently considered to be TRUE.  If this is one of the nodes added by
  3375.    `add_values_to_cover', all the EQ_ATTR tests in the original expression
  3376.    will be FALSE.  Otherwise, only the CURRENT_VALUE will be true.
  3377.  
  3378.    NUM_VALUES is simply the length of the VALUES list and is there for
  3379.    convenience.
  3380.  
  3381.    Once the dimensions are created, the algorithm enumerates all possible
  3382.    values and computes the current value of the given expression.  */
  3383.  
  3384. struct dimension 
  3385. {
  3386.   struct attr_desc *attr;    /* Attribute for this dimension.  */
  3387.   rtx values;            /* List of attribute values used.  */
  3388.   rtx current_value;        /* Position in the list for the TRUE value.  */
  3389.   int num_values;        /* Length of the values list.  */
  3390. };
  3391.  
  3392. /* If EXP is a suitable expression, reorganize it by constructing an
  3393.    equivalent expression that is a COND with the tests being all combinations
  3394.    of attribute values and the values being simple constants.  */
  3395.  
  3396. static rtx
  3397. simplify_by_exploding (exp)
  3398.      rtx exp;
  3399. {
  3400.   rtx list = 0, link, condexp, defval;
  3401.   struct dimension *space;
  3402.   rtx *condtest, *condval;
  3403.   int i, j, total, ndim = 0;
  3404.   int most_tests, num_marks, new_marks;
  3405.  
  3406.   /* Locate all the EQ_ATTR expressions.  */
  3407.   if (! find_and_mark_used_attributes (exp, &list, &ndim) || ndim == 0)
  3408.     {
  3409.       unmark_used_attributes (list, 0, 0);
  3410.       return exp;
  3411.     }
  3412.  
  3413.   /* Create an attribute space from the list of used attributes.  For each
  3414.      dimension in the attribute space, record the attribute, list of values
  3415.      used, and number of values used.  Add members to the list of values to
  3416.      cover the domain of the attribute.  This makes the expanded COND form
  3417.      order independent.  */
  3418.  
  3419.   space = (struct dimension *) alloca (ndim * sizeof (struct dimension));
  3420.  
  3421.   total = 1;
  3422.   for (ndim = 0; list; ndim++)
  3423.     {
  3424.       /* Pull the first attribute value from the list and record that
  3425.      attribute as another dimension in the attribute space.  */
  3426.       char *name = XSTR (XEXP (list, 0), 0);
  3427.       rtx *prev;
  3428.  
  3429.       if ((space[ndim].attr = find_attr (name, 0)) == 0
  3430.       || space[ndim].attr->is_numeric)
  3431.     {
  3432.       unmark_used_attributes (list, space, ndim);
  3433.       return exp;
  3434.     }
  3435.  
  3436.       /* Add all remaining attribute values that refer to this attribute.  */
  3437.       space[ndim].num_values = 0;
  3438.       space[ndim].values = 0;
  3439.       prev = &list;
  3440.       for (link = list; link; link = *prev)
  3441.     if (! strcmp (XSTR (XEXP (link, 0), 0), name))
  3442.       {
  3443.         space[ndim].num_values++;
  3444.         *prev = XEXP (link, 1);
  3445.         XEXP (link, 1) = space[ndim].values;
  3446.         space[ndim].values = link;
  3447.       }
  3448.     else
  3449.       prev = &XEXP (link, 1);
  3450.  
  3451.       /* Add sufficient members to the list of values to make the list
  3452.      mutually exclusive and record the total size of the attribute
  3453.      space.  */
  3454.       total *= add_values_to_cover (&space[ndim]);
  3455.     }
  3456.  
  3457.   /* Sort the attribute space so that the attributes go from non-constant
  3458.      to constant and from most values to least values.  */
  3459.   for (i = 0; i < ndim; i++)
  3460.     for (j = ndim - 1; j > i; j--)
  3461.       if ((space[j-1].attr->is_const && !space[j].attr->is_const)
  3462.       || space[j-1].num_values < space[j].num_values)
  3463.     {
  3464.       struct dimension tmp;
  3465.       tmp = space[j];
  3466.       space[j] = space[j-1];
  3467.       space[j-1] = tmp;
  3468.     }
  3469.  
  3470.   /* Establish the initial current value.  */
  3471.   for (i = 0; i < ndim; i++)
  3472.     space[i].current_value = space[i].values;
  3473.  
  3474.   condtest = (rtx *) alloca (total * sizeof (rtx));
  3475.   condval = (rtx *) alloca (total * sizeof (rtx));
  3476.  
  3477.   /* Expand the tests and values by iterating over all values in the
  3478.      attribute space.  */
  3479.   for (i = 0;; i++)
  3480.     {
  3481.       condtest[i] = test_for_current_value (space, ndim);
  3482.       condval[i] = simplify_with_current_value (exp, space, ndim);
  3483.       if (! increment_current_value (space, ndim))
  3484.     break;
  3485.     }
  3486.   if (i != total - 1)
  3487.     abort ();
  3488.  
  3489.   /* We are now finished with the original expression.  */
  3490.   unmark_used_attributes (0, space, ndim);
  3491.  
  3492.   /* Find the most used constant value and make that the default.  */
  3493.   most_tests = -1;
  3494.   for (i = num_marks = 0; i < total; i++)
  3495.     if (GET_CODE (condval[i]) == CONST_STRING
  3496.     && ! MEM_VOLATILE_P (condval[i]))
  3497.       {
  3498.     /* Mark the unmarked constant value and count how many are marked.  */
  3499.     MEM_VOLATILE_P (condval[i]) = 1;
  3500.     for (j = new_marks = 0; j < total; j++)
  3501.       if (GET_CODE (condval[j]) == CONST_STRING
  3502.           && MEM_VOLATILE_P (condval[j]))
  3503.         new_marks++;
  3504.     if (new_marks - num_marks > most_tests)
  3505.       {
  3506.         most_tests = new_marks - num_marks;
  3507.         defval = condval[i];
  3508.       }
  3509.     num_marks = new_marks;
  3510.       }
  3511.   /* Clear all the marks.  */
  3512.   for (i = 0; i < total; i++)
  3513.     MEM_VOLATILE_P (condval[i]) = 0;
  3514.  
  3515.   /* Give up if nothing is constant.  */
  3516.   if (num_marks == 0)
  3517.     return exp;
  3518.  
  3519.   /* If all values are the default, use that.  */
  3520.   if (total == most_tests)
  3521.     return defval;
  3522.  
  3523.   /* Make a COND with the most common constant value the default.  (A more
  3524.      complex method where tests with the same value were combined didn't
  3525.      seem to improve things.)  */
  3526.   condexp = rtx_alloc (COND);
  3527.   XVEC (condexp, 0) = rtvec_alloc ((total - most_tests) * 2);
  3528.   XEXP (condexp, 1) = defval;
  3529.   for (i = j = 0; i < total; i++)
  3530.     if (condval[i] != defval)
  3531.       {
  3532.     XVECEXP (condexp, 0, 2 * j) = condtest[i];
  3533.     XVECEXP (condexp, 0, 2 * j + 1) = condval[i];
  3534.     j++;
  3535.       }
  3536.  
  3537.   return condexp;
  3538. }
  3539.  
  3540. /* Set the MEM_VOLATILE_P flag for all EQ_ATTR expressions in EXP and
  3541.    verify that EXP can be simplified to a constant term if all the EQ_ATTR
  3542.    tests have known value.  */
  3543.  
  3544. static int
  3545. find_and_mark_used_attributes (exp, terms, nterms)
  3546.      rtx exp, *terms;
  3547.      int *nterms;
  3548. {
  3549.   int i;
  3550.  
  3551.   switch (GET_CODE (exp))
  3552.     {
  3553.     case EQ_ATTR:
  3554.       if (! MEM_VOLATILE_P (exp))
  3555.     {
  3556.       rtx link = rtx_alloc (EXPR_LIST);
  3557.       XEXP (link, 0) = exp;
  3558.       XEXP (link, 1) = *terms;
  3559.       *terms = link;
  3560.       *nterms += 1;
  3561.       MEM_VOLATILE_P (exp) = 1;
  3562.     }
  3563.     case CONST_STRING:
  3564.       return 1;
  3565.  
  3566.     case IF_THEN_ELSE:
  3567.       if (! find_and_mark_used_attributes (XEXP (exp, 2), terms, nterms))
  3568.     return 0;
  3569.     case IOR:
  3570.     case AND:
  3571.       if (! find_and_mark_used_attributes (XEXP (exp, 1), terms, nterms))
  3572.     return 0;
  3573.     case NOT:
  3574.       if (! find_and_mark_used_attributes (XEXP (exp, 0), terms, nterms))
  3575.     return 0;
  3576.       return 1;
  3577.  
  3578.     case COND:
  3579.       for (i = 0; i < XVECLEN (exp, 0); i++)
  3580.     if (! find_and_mark_used_attributes (XVECEXP (exp, 0, i), terms, nterms))
  3581.       return 0;
  3582.       if (! find_and_mark_used_attributes (XEXP (exp, 1), terms, nterms))
  3583.     return 0;
  3584.       return 1;
  3585.     }
  3586.  
  3587.   return 0;
  3588. }
  3589.  
  3590. /* Clear the MEM_VOLATILE_P flag in all EQ_ATTR expressions on LIST and
  3591.    in the values of the NDIM-dimensional attribute space SPACE.  */
  3592.  
  3593. static void
  3594. unmark_used_attributes (list, space, ndim)
  3595.      rtx list;
  3596.      struct dimension *space;
  3597.      int ndim;
  3598. {
  3599.   rtx link, exp;
  3600.   int i;
  3601.  
  3602.   for (i = 0; i < ndim; i++)
  3603.     unmark_used_attributes (space[i].values, 0, 0);
  3604.  
  3605.   for (link = list; link; link = XEXP (link, 1))
  3606.     {
  3607.       exp = XEXP (link, 0);
  3608.       if (GET_CODE (exp) == EQ_ATTR)
  3609.     MEM_VOLATILE_P (exp) = 0;
  3610.     }
  3611. }
  3612.  
  3613. /* Update the attribute dimension DIM so that all values of the attribute
  3614.    are tested.  Return the updated number of values.  */
  3615.  
  3616. static int
  3617. add_values_to_cover (dim)
  3618.      struct dimension *dim;
  3619. {
  3620.   struct attr_value *av;
  3621.   rtx exp, link, *prev;
  3622.   int nalt = 0;
  3623.  
  3624.   for (av = dim->attr->first_value; av; av = av->next)
  3625.     if (GET_CODE (av->value) == CONST_STRING)
  3626.       nalt++;
  3627.  
  3628.   if (nalt < dim->num_values)
  3629.     abort ();
  3630.   else if (nalt == dim->num_values)
  3631.     ; /* Ok.  */
  3632.   else if (nalt * 2 < dim->num_values * 3)
  3633.     {
  3634.       /* Most all the values of the attribute are used, so add all the unused
  3635.      values.  */
  3636.       prev = &dim->values;
  3637.       for (link = dim->values; link; link = *prev)
  3638.     prev = &XEXP (link, 1);
  3639.  
  3640.       for (av = dim->attr->first_value; av; av = av->next)
  3641.     if (GET_CODE (av->value) == CONST_STRING)
  3642.       {
  3643.         exp = attr_eq (dim->attr->name, XSTR (av->value, 0));
  3644.         if (MEM_VOLATILE_P (exp))
  3645.           continue;
  3646.  
  3647.         link = rtx_alloc (EXPR_LIST);
  3648.         XEXP (link, 0) = exp;
  3649.         XEXP (link, 1) = 0;
  3650.         *prev = link;
  3651.         prev = &XEXP (link, 1);
  3652.       }
  3653.       dim->num_values = nalt;
  3654.     }
  3655.   else
  3656.     {
  3657.       rtx orexp = false_rtx;
  3658.  
  3659.       /* Very few values are used, so compute a mutually exclusive
  3660.      expression.  (We could do this for numeric values if that becomes
  3661.      important.)  */
  3662.       prev = &dim->values;
  3663.       for (link = dim->values; link; link = *prev)
  3664.     {
  3665.       orexp = insert_right_side (IOR, orexp, XEXP (link, 0), -2);
  3666.       prev = &XEXP (link, 1);
  3667.     }
  3668.       link = rtx_alloc (EXPR_LIST);
  3669.       XEXP (link, 0) = attr_rtx (NOT, orexp);
  3670.       XEXP (link, 1) = 0;
  3671.       *prev = link;
  3672.       dim->num_values++;
  3673.     }
  3674.   return dim->num_values;
  3675. }
  3676.  
  3677. /* Increment the current value for the NDIM-dimensional attribute space SPACE
  3678.    and return FALSE if the increment overflowed.  */
  3679.  
  3680. static int
  3681. increment_current_value (space, ndim)
  3682.      struct dimension *space;
  3683.      int ndim;
  3684. {
  3685.   int i;
  3686.  
  3687.   for (i = ndim - 1; i >= 0; i--)
  3688.     {
  3689.       if ((space[i].current_value = XEXP (space[i].current_value, 1)) == 0)
  3690.     space[i].current_value = space[i].values;
  3691.       else
  3692.     return 1;
  3693.     }
  3694.   return 0;
  3695. }
  3696.  
  3697. /* Construct an expression corresponding to the current value for the
  3698.    NDIM-dimensional attribute space SPACE.  */
  3699.  
  3700. static rtx
  3701. test_for_current_value (space, ndim)
  3702.      struct dimension *space;
  3703.      int ndim;
  3704. {
  3705.   int i;
  3706.   rtx exp = true_rtx;
  3707.  
  3708.   for (i = 0; i < ndim; i++)
  3709.     exp = insert_right_side (AND, exp, XEXP (space[i].current_value, 0), -2);
  3710.  
  3711.   return exp;
  3712. }
  3713.  
  3714. /* Given the current value of the NDIM-dimensional attribute space SPACE,
  3715.    set the corresponding EQ_ATTR expressions to that value and reduce
  3716.    the expression EXP as much as possible.  On input [and output], all
  3717.    known EQ_ATTR expressions are set to FALSE.  */
  3718.  
  3719. static rtx
  3720. simplify_with_current_value (exp, space, ndim)
  3721.      rtx exp;
  3722.      struct dimension *space;
  3723.      int ndim;
  3724. {
  3725.   int i;
  3726.   rtx x;
  3727.  
  3728.   /* Mark each current value as TRUE.  */
  3729.   for (i = 0; i < ndim; i++)
  3730.     {
  3731.       x = XEXP (space[i].current_value, 0);
  3732.       if (GET_CODE (x) == EQ_ATTR)
  3733.     MEM_VOLATILE_P (x) = 0;
  3734.     }
  3735.  
  3736.   exp = simplify_with_current_value_aux (exp);
  3737.  
  3738.   /* Change each current value back to FALSE.  */
  3739.   for (i = 0; i < ndim; i++)
  3740.     {
  3741.       x = XEXP (space[i].current_value, 0);
  3742.       if (GET_CODE (x) == EQ_ATTR)
  3743.     MEM_VOLATILE_P (x) = 1;
  3744.     }
  3745.  
  3746.   return exp;
  3747. }
  3748.  
  3749. /* Reduce the expression EXP based on the MEM_VOLATILE_P settings of
  3750.    all EQ_ATTR expressions.  */
  3751.  
  3752. static rtx
  3753. simplify_with_current_value_aux (exp)
  3754.      rtx exp;
  3755. {
  3756.   register int i;
  3757.   rtx cond;
  3758.  
  3759.   switch (GET_CODE (exp))
  3760.     {
  3761.     case EQ_ATTR:
  3762.       if (MEM_VOLATILE_P (exp))
  3763.     return false_rtx;
  3764.       else
  3765.     return true_rtx;
  3766.     case CONST_STRING:
  3767.       return exp;
  3768.  
  3769.     case IF_THEN_ELSE:
  3770.       cond = simplify_with_current_value_aux (XEXP (exp, 0));
  3771.       if (cond == true_rtx)
  3772.     return simplify_with_current_value_aux (XEXP (exp, 1));
  3773.       else if (cond == false_rtx)
  3774.     return simplify_with_current_value_aux (XEXP (exp, 2));
  3775.       else
  3776.     return attr_rtx (IF_THEN_ELSE, cond,
  3777.              simplify_with_current_value_aux (XEXP (exp, 1)),
  3778.              simplify_with_current_value_aux (XEXP (exp, 2)));
  3779.  
  3780.     case IOR:
  3781.       cond = simplify_with_current_value_aux (XEXP (exp, 1));
  3782.       if (cond == true_rtx)
  3783.     return cond;
  3784.       else if (cond == false_rtx)
  3785.     return simplify_with_current_value_aux (XEXP (exp, 0));
  3786.       else
  3787.     return attr_rtx (IOR, cond,
  3788.              simplify_with_current_value_aux (XEXP (exp, 0)));
  3789.  
  3790.     case AND:
  3791.       cond = simplify_with_current_value_aux (XEXP (exp, 1));
  3792.       if (cond == true_rtx)
  3793.     return simplify_with_current_value_aux (XEXP (exp, 0));
  3794.       else if (cond == false_rtx)
  3795.     return cond;
  3796.       else
  3797.     return attr_rtx (AND, cond,
  3798.              simplify_with_current_value_aux (XEXP (exp, 0)));
  3799.  
  3800.     case NOT:
  3801.       cond = simplify_with_current_value_aux (XEXP (exp, 0));
  3802.       if (cond == true_rtx)
  3803.     return false_rtx;
  3804.       else if (cond == false_rtx)
  3805.     return true_rtx;
  3806.       else
  3807.     return attr_rtx (NOT, cond);
  3808.  
  3809.     case COND:
  3810.       for (i = 0; i < XVECLEN (exp, 0); i += 2)
  3811.     {
  3812.       cond = simplify_with_current_value_aux (XVECEXP (exp, 0, i));
  3813.       if (cond == true_rtx)
  3814.         return simplify_with_current_value_aux (XVECEXP (exp, 0, i + 1));
  3815.       else if (cond == false_rtx)
  3816.         continue;
  3817.       else
  3818.         abort (); /* With all EQ_ATTR's of known value, a case should
  3819.              have been selected.  */
  3820.     }
  3821.       return simplify_with_current_value_aux (XEXP (exp, 1));
  3822.     }
  3823.   abort ();
  3824. }
  3825.  
  3826. /* Clear the MEM_IN_STRUCT_P flag in EXP and its subexpressions.  */
  3827.  
  3828. clear_struct_flag (x)
  3829.      rtx x;
  3830. {
  3831.   register int i;
  3832.   register int j;
  3833.   register enum rtx_code code;
  3834.   register char *fmt;
  3835.  
  3836.   MEM_IN_STRUCT_P (x) = 0;
  3837.   if (RTX_UNCHANGING_P (x))
  3838.     return;
  3839.  
  3840.   code = GET_CODE (x);
  3841.  
  3842.   switch (code)
  3843.     {
  3844.     case REG:
  3845.     case QUEUED:
  3846.     case CONST_INT:
  3847.     case CONST_DOUBLE:
  3848.     case SYMBOL_REF:
  3849.     case CODE_LABEL:
  3850.     case PC:
  3851.     case CC0:
  3852.     case EQ_ATTR:
  3853.       return;
  3854.     }
  3855.  
  3856.   /* Compare the elements.  If any pair of corresponding elements
  3857.      fail to match, return 0 for the whole things.  */
  3858.  
  3859.   fmt = GET_RTX_FORMAT (code);
  3860.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3861.     {
  3862.       switch (fmt[i])
  3863.     {
  3864.     case 'V':
  3865.     case 'E':
  3866.       for (j = 0; j < XVECLEN (x, i); j++)
  3867.         clear_struct_flag (XVECEXP (x, i, j));
  3868.       break;
  3869.  
  3870.     case 'e':
  3871.       clear_struct_flag (XEXP (x, i));
  3872.       break;
  3873.     }
  3874.     }
  3875. }
  3876.  
  3877. /* Return the number of RTX objects making up the expression X.
  3878.    But if we count more more than MAX objects, stop counting.  */
  3879.  
  3880. count_sub_rtxs (x, max)
  3881.      rtx x;
  3882.      int max;
  3883. {
  3884.   register int i;
  3885.   register int j;
  3886.   register enum rtx_code code;
  3887.   register char *fmt;
  3888.   int total = 0;
  3889.  
  3890.   code = GET_CODE (x);
  3891.  
  3892.   switch (code)
  3893.     {
  3894.     case REG:
  3895.     case QUEUED:
  3896.     case CONST_INT:
  3897.     case CONST_DOUBLE:
  3898.     case SYMBOL_REF:
  3899.     case CODE_LABEL:
  3900.     case PC:
  3901.     case CC0:
  3902.     case EQ_ATTR:
  3903.       return 1;
  3904.     }
  3905.  
  3906.   /* Compare the elements.  If any pair of corresponding elements
  3907.      fail to match, return 0 for the whole things.  */
  3908.  
  3909.   fmt = GET_RTX_FORMAT (code);
  3910.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3911.     {
  3912.       if (total >= max)
  3913.     return total;
  3914.  
  3915.       switch (fmt[i])
  3916.     {
  3917.     case 'V':
  3918.     case 'E':
  3919.       for (j = 0; j < XVECLEN (x, i); j++)
  3920.         total += count_sub_rtxs (XVECEXP (x, i, j), max);
  3921.       break;
  3922.  
  3923.     case 'e':
  3924.       total += count_sub_rtxs (XEXP (x, i), max);
  3925.       break;
  3926.     }
  3927.     }
  3928.   return total;
  3929.  
  3930. }
  3931.  
  3932. #ifdef MPW
  3933. #pragma segment GENAT02
  3934. #endif
  3935.  
  3936. /* Create table entries for DEFINE_ATTR.  */
  3937.  
  3938. static void
  3939. gen_attr (exp)
  3940.      rtx exp;
  3941. {
  3942.   struct attr_desc *attr;
  3943.   struct attr_value *av;
  3944.   char *name_ptr;
  3945.   char *p;
  3946.  
  3947.   /* Make a new attribute structure.  Check for duplicate by looking at
  3948.      attr->default_val, since it is initialized by this routine.  */
  3949.   attr = find_attr (XSTR (exp, 0), 1);
  3950.   if (attr->default_val)
  3951.     fatal ("Duplicate definition for `%s' attribute", attr->name);
  3952.  
  3953.   if (*XSTR (exp, 1) == '\0')
  3954.       attr->is_numeric = 1;
  3955.   else
  3956.     {
  3957.       name_ptr = XSTR (exp, 1);
  3958.       while ((p = next_comma_elt (&name_ptr)) != NULL)
  3959.     {
  3960.       av = (struct attr_value *) oballoc (sizeof (struct attr_value));
  3961.       av->value = attr_rtx (CONST_STRING, p);
  3962.       av->next = attr->first_value;
  3963.       attr->first_value = av;
  3964.       av->first_insn = NULL;
  3965.       av->num_insns = 0;
  3966.       av->has_asm_insn = 0;
  3967.     }
  3968.     }
  3969.  
  3970.   if (GET_CODE (XEXP (exp, 2)) == CONST)
  3971.     {
  3972.       attr->is_const = 1;
  3973.       if (attr->is_numeric)
  3974.     fatal ("Constant attributes may not take numeric values");
  3975.       /* Get rid of the CONST node.  It is allowed only at top-level.  */
  3976.       XEXP (exp, 2) = XEXP (XEXP (exp, 2), 0);
  3977.     }
  3978.  
  3979.   if (! strcmp (attr->name, "length") && ! attr->is_numeric)
  3980.     fatal ("`length' attribute must take numeric values");
  3981.  
  3982.   /* Set up the default value. */
  3983.   XEXP (exp, 2) = check_attr_value (XEXP (exp, 2), attr);
  3984.   attr->default_val = get_attr_value (XEXP (exp, 2), attr, -2);
  3985. }
  3986.  
  3987. /* Given a pattern for DEFINE_PEEPHOLE or DEFINE_INSN, return the number of
  3988.    alternatives in the constraints.  Assume all MATCH_OPERANDs have the same
  3989.    number of alternatives as this should be checked elsewhere.  */
  3990.  
  3991. static int
  3992. count_alternatives (exp)
  3993.      rtx exp;
  3994. {
  3995.   int i, j, n;
  3996.   char *fmt;
  3997.   
  3998.   if (GET_CODE (exp) == MATCH_OPERAND)
  3999.     return n_comma_elts (XSTR (exp, 2));
  4000.  
  4001.   for (i = 0, fmt = GET_RTX_FORMAT (GET_CODE (exp));
  4002.        i < GET_RTX_LENGTH (GET_CODE (exp)); i++)
  4003.     switch (*fmt++)
  4004.       {
  4005.       case 'e':
  4006.       case 'u':
  4007.     n = count_alternatives (XEXP (exp, i));
  4008.     if (n)
  4009.       return n;
  4010.     break;
  4011.  
  4012.       case 'E':
  4013.       case 'V':
  4014.     if (XVEC (exp, i) != NULL)
  4015.       for (j = 0; j < XVECLEN (exp, i); j++)
  4016.         {
  4017.           n = count_alternatives (XVECEXP (exp, i, j));
  4018.           if (n)
  4019.         return n;
  4020.         }
  4021.       }
  4022.  
  4023.   return 0;
  4024. }
  4025.  
  4026. /* Returns non-zero if the given expression contains an EQ_ATTR with the
  4027.    `alternative' attribute.  */
  4028.  
  4029. static int
  4030. compares_alternatives_p (exp)
  4031.      rtx exp;
  4032. {
  4033.   int i, j;
  4034.   char *fmt;
  4035.  
  4036.   if (GET_CODE (exp) == EQ_ATTR && XSTR (exp, 0) == alternative_name)
  4037.     return 1;
  4038.  
  4039.   for (i = 0, fmt = GET_RTX_FORMAT (GET_CODE (exp));
  4040.        i < GET_RTX_LENGTH (GET_CODE (exp)); i++)
  4041.     switch (*fmt++)
  4042.       {
  4043.       case 'e':
  4044.       case 'u':
  4045.     if (compares_alternatives_p (XEXP (exp, i)))
  4046.       return 1;
  4047.     break;
  4048.  
  4049.       case 'E':
  4050.     for (j = 0; j < XVECLEN (exp, i); j++)
  4051.       if (compares_alternatives_p (XVECEXP (exp, i, j)))
  4052.         return 1;
  4053.     break;
  4054.       }
  4055.  
  4056.   return 0;
  4057. }
  4058.  
  4059. /* Returns non-zero is INNER is contained in EXP.  */
  4060.  
  4061. static int
  4062. contained_in_p (inner, exp)
  4063.      rtx inner;
  4064.      rtx exp;
  4065. {
  4066.   int i, j;
  4067.   char *fmt;
  4068.  
  4069.   if (rtx_equal_p (inner, exp))
  4070.     return 1;
  4071.  
  4072.   for (i = 0, fmt = GET_RTX_FORMAT (GET_CODE (exp));
  4073.        i < GET_RTX_LENGTH (GET_CODE (exp)); i++)
  4074.     switch (*fmt++)
  4075.       {
  4076.       case 'e':
  4077.       case 'u':
  4078.     if (contained_in_p (inner, XEXP (exp, i)))
  4079.       return 1;
  4080.     break;
  4081.  
  4082.       case 'E':
  4083.     for (j = 0; j < XVECLEN (exp, i); j++)
  4084.       if (contained_in_p (inner, XVECEXP (exp, i, j)))
  4085.         return 1;
  4086.     break;
  4087.       }
  4088.  
  4089.   return 0;
  4090. }
  4091.     
  4092. /* Process DEFINE_PEEPHOLE, DEFINE_INSN, and DEFINE_ASM_ATTRIBUTES.  */
  4093.  
  4094. static void
  4095. gen_insn (exp)
  4096.      rtx exp;
  4097. {
  4098.   struct insn_def *id;
  4099.  
  4100.   id = (struct insn_def *) oballoc (sizeof (struct insn_def));
  4101.   id->next = defs;
  4102.   defs = id;
  4103.   id->def = exp;
  4104.  
  4105.   switch (GET_CODE (exp))
  4106.     {
  4107.     case DEFINE_INSN:
  4108.       id->insn_code = insn_code_number++;
  4109.       id->insn_index = insn_index_number++;
  4110.       id->num_alternatives = count_alternatives (exp);
  4111.       if (id->num_alternatives == 0)
  4112.     id->num_alternatives = 1;
  4113.       id->vec_idx = 4;
  4114.       break;
  4115.  
  4116.     case DEFINE_PEEPHOLE:
  4117.       id->insn_code = insn_code_number++;
  4118.       id->insn_index = insn_index_number++;
  4119.       id->num_alternatives = count_alternatives (exp);
  4120.       if (id->num_alternatives == 0)
  4121.     id->num_alternatives = 1;
  4122.       id->vec_idx = 3;
  4123.       break;
  4124.  
  4125.     case DEFINE_ASM_ATTRIBUTES:
  4126.       id->insn_code = -1;
  4127.       id->insn_index = -1;
  4128.       id->num_alternatives = 1;
  4129.       id->vec_idx = 0;
  4130.       got_define_asm_attributes = 1;
  4131.       break;
  4132.     }
  4133. }
  4134.  
  4135. /* Process a DEFINE_DELAY.  Validate the vector length, check if annul
  4136.    true or annul false is specified, and make a `struct delay_desc'.  */
  4137.  
  4138. static void
  4139. gen_delay (def)
  4140.      rtx def;
  4141. {
  4142.   struct delay_desc *delay;
  4143.   int i;
  4144.  
  4145.   if (XVECLEN (def, 1) % 3 != 0)
  4146.     fatal ("Number of elements in DEFINE_DELAY must be multiple of three.");
  4147.  
  4148.   for (i = 0; i < XVECLEN (def, 1); i += 3)
  4149.     {
  4150.       if (XVECEXP (def, 1, i + 1))
  4151.     have_annul_true = 1;
  4152.       if (XVECEXP (def, 1, i + 2))
  4153.     have_annul_false = 1;
  4154.     }
  4155.   
  4156.   delay = (struct delay_desc *) oballoc (sizeof (struct delay_desc));
  4157.   delay->def = def;
  4158.   delay->num = ++num_delays;
  4159.   delay->next = delays;
  4160.   delays = delay;
  4161. }
  4162.  
  4163. /* Process a DEFINE_FUNCTION_UNIT.  
  4164.  
  4165.    This gives information about a function unit contained in the CPU.
  4166.    We fill in a `struct function_unit_op' and a `struct function_unit'
  4167.    with information used later by `expand_unit'.  */
  4168.  
  4169. static void
  4170. gen_unit (def)
  4171.      rtx def;
  4172. {
  4173.   struct function_unit *unit;
  4174.   struct function_unit_op *op;
  4175.   char *name = XSTR (def, 0);
  4176.   int multiplicity = XINT (def, 1);
  4177.   int simultaneity = XINT (def, 2);
  4178.   rtx condexp = XEXP (def, 3);
  4179.   int ready_cost = MAX (XINT (def, 4), 1);
  4180.   int issue_delay = MAX (XINT (def, 5), 1);
  4181.  
  4182.   /* See if we have already seen this function unit.  If so, check that
  4183.      the multiplicity and simultaneity values are the same.  If not, make
  4184.      a structure for this function unit.  */
  4185.   for (unit = units; unit; unit = unit->next)
  4186.     if (! strcmp (unit->name, name))
  4187.       {
  4188.     if (unit->multiplicity != multiplicity
  4189.         || unit->simultaneity != simultaneity)
  4190.       fatal ("Differing specifications given for `%s' function unit.",
  4191.          unit->name);
  4192.     break;
  4193.       }
  4194.  
  4195.   if (unit == 0)
  4196.     {
  4197.       unit = (struct function_unit *) oballoc (sizeof (struct function_unit));
  4198.       unit->name = name;
  4199.       unit->multiplicity = multiplicity;
  4200.       unit->simultaneity = simultaneity;
  4201.       unit->issue_delay.min = unit->issue_delay.max = issue_delay;
  4202.       unit->num = num_units++;
  4203.       unit->num_opclasses = 0;
  4204.       unit->condexp = false_rtx;
  4205.       unit->ops = 0;
  4206.       unit->next = units;
  4207.       units = unit;
  4208.     }
  4209.  
  4210.   /* Make a new operation class structure entry and initialize it.  */
  4211.   op = (struct function_unit_op *) oballoc (sizeof (struct function_unit_op));
  4212.   op->condexp = condexp;
  4213.   op->num = unit->num_opclasses++;
  4214.   op->ready = ready_cost;
  4215.   op->issue_delay = issue_delay;
  4216.   op->next = unit->ops;
  4217.   unit->ops = op;
  4218.  
  4219.   /* Set our issue expression based on whether or not an optional conflict
  4220.      vector was specified.  */
  4221.   if (XVEC (def, 6))
  4222.     {
  4223.       /* Compute the IOR of all the specified expressions.  */
  4224.       rtx orexp = false_rtx;
  4225.       int i;
  4226.  
  4227.       for (i = 0; i < XVECLEN (def, 6); i++)
  4228.     orexp = insert_right_side (IOR, orexp, XVECEXP (def, 6, i), -2);
  4229.  
  4230.       op->conflict_exp = orexp;
  4231.       extend_range (&unit->issue_delay, 1, issue_delay);
  4232.     }
  4233.   else
  4234.     {
  4235.       op->conflict_exp = true_rtx;
  4236.       extend_range (&unit->issue_delay, issue_delay, issue_delay);
  4237.     }
  4238.  
  4239.   /* Merge our conditional into that of the function unit so we can determine
  4240.      which insns are used by the function unit.  */
  4241.   unit->condexp = insert_right_side (IOR, unit->condexp, op->condexp, -2);
  4242. }
  4243.  
  4244. /* Given a piece of RTX, print a C expression to test it's truth value.
  4245.    We use AND and IOR both for logical and bit-wise operations, so 
  4246.    interpret them as logical unless they are inside a comparison expression.
  4247.    The second operand of this function will be non-zero in that case.  */
  4248.  
  4249. static void
  4250. write_test_expr (exp, in_comparison)
  4251.      rtx exp;
  4252.      int in_comparison;
  4253. {
  4254.   int comparison_operator = 0;
  4255.   RTX_CODE code;
  4256.   struct attr_desc *attr;
  4257.  
  4258.   /* In order not to worry about operator precedence, surround our part of
  4259.      the expression with parentheses.  */
  4260.  
  4261.   printf ("(");
  4262.   code = GET_CODE (exp);
  4263.   switch (code)
  4264.     {
  4265.     /* Binary operators.  */
  4266.     case EQ: case NE:
  4267.     case GE: case GT: case GEU: case GTU:
  4268.     case LE: case LT: case LEU: case LTU:
  4269.       comparison_operator = 1;
  4270.  
  4271.     case PLUS:   case MINUS:  case MULT:     case DIV:      case MOD:
  4272.     case AND:    case IOR:    case XOR:
  4273.     case LSHIFT: case ASHIFT: case LSHIFTRT: case ASHIFTRT:
  4274.       write_test_expr (XEXP (exp, 0), in_comparison || comparison_operator);
  4275.       switch (code)
  4276.         {
  4277.     case EQ:
  4278.       printf (" == ");
  4279.       break;
  4280.     case NE:
  4281.       printf (" != ");
  4282.       break;
  4283.     case GE:
  4284.       printf (" >= ");
  4285.       break;
  4286.     case GT:
  4287.       printf (" > ");
  4288.       break;
  4289.     case GEU:
  4290.       printf (" >= (unsigned) ");
  4291.       break;
  4292.     case GTU:
  4293.       printf (" > (unsigned) ");
  4294.       break;
  4295.     case LE:
  4296.       printf (" <= ");
  4297.       break;
  4298.     case LT:
  4299.       printf (" < ");
  4300.       break;
  4301.     case LEU:
  4302.       printf (" <= (unsigned) ");
  4303.       break;
  4304.     case LTU:
  4305.       printf (" < (unsigned) ");
  4306.       break;
  4307.     case PLUS:
  4308.       printf (" + ");
  4309.       break;
  4310.     case MINUS:
  4311.       printf (" - ");
  4312.       break;
  4313.     case MULT:
  4314.       printf (" * ");
  4315.       break;
  4316.     case DIV:
  4317.       printf (" / ");
  4318.       break;
  4319.     case MOD:
  4320.       printf (" %% ");
  4321.       break;
  4322.     case AND:
  4323.       if (in_comparison)
  4324.         printf (" & ");
  4325.       else
  4326.         printf (" && ");
  4327.       break;
  4328.     case IOR:
  4329.       if (in_comparison)
  4330.         printf (" | ");
  4331.       else
  4332.         printf (" || ");
  4333.       break;
  4334.     case XOR:
  4335.       printf (" ^ ");
  4336.       break;
  4337.     case LSHIFT:
  4338.     case ASHIFT:
  4339.       printf (" << ");
  4340.       break;
  4341.     case LSHIFTRT:
  4342.     case ASHIFTRT:
  4343.       printf (" >> ");
  4344.       break;
  4345.         }
  4346.  
  4347.       write_test_expr (XEXP (exp, 1), in_comparison || comparison_operator);
  4348.       break;
  4349.  
  4350.     case NOT:
  4351.       /* Special-case (not (eq_attrq "alternative" "x")) */
  4352.       if (! in_comparison && GET_CODE (XEXP (exp, 0)) == EQ_ATTR
  4353.       && XSTR (XEXP (exp, 0), 0) == alternative_name)
  4354.     {
  4355.       printf ("which_alternative != %s", XSTR (XEXP (exp, 0), 1));
  4356.       break;
  4357.     }
  4358.  
  4359.       /* Otherwise, fall through to normal unary operator.  */
  4360.  
  4361.     /* Unary operators.  */   
  4362.     case ABS:  case NEG:
  4363.       switch (code)
  4364.     {
  4365.     case NOT:
  4366.       if (in_comparison)
  4367.         printf ("~ ");
  4368.       else
  4369.         printf ("! ");
  4370.       break;
  4371.     case ABS:
  4372.       printf ("abs ");
  4373.       break;
  4374.     case NEG:
  4375.       printf ("-");
  4376.       break;
  4377.     }
  4378.  
  4379.       write_test_expr (XEXP (exp, 0), in_comparison);
  4380.       break;
  4381.  
  4382.     /* Comparison test of an attribute with a value.  Most of these will
  4383.        have been removed by optimization.   Handle "alternative"
  4384.        specially and give error if EQ_ATTR present inside a comparison.  */
  4385.     case EQ_ATTR:
  4386.       if (in_comparison)
  4387.     fatal ("EQ_ATTR not valid inside comparison");
  4388.  
  4389.       if (XSTR (exp, 0) == alternative_name)
  4390.     {
  4391.       printf ("which_alternative == %s", XSTR (exp, 1));
  4392.       break;
  4393.     }
  4394.  
  4395.       attr = find_attr (XSTR (exp, 0), 0);
  4396.       if (! attr) abort ();
  4397.  
  4398.       /* Now is the time to expand the value of a constant attribute.  */
  4399.       if (attr->is_const)
  4400.     {
  4401.       write_test_expr (evaluate_eq_attr (exp, attr->default_val->value,
  4402.                          0, 0),
  4403.                in_comparison);
  4404.     }
  4405.       else
  4406.     {
  4407.       printf ("get_attr_%s (insn) == ", attr->name);
  4408.       write_attr_valueq (attr, XSTR (exp, 1)); 
  4409.     }
  4410.       break;
  4411.  
  4412.     /* See if an operand matches a predicate.  */
  4413.     case MATCH_OPERAND:
  4414.       /* If only a mode is given, just ensure the mode matches the operand.
  4415.      If neither a mode nor predicate is given, error.  */
  4416.      if (XSTR (exp, 1) == NULL || *XSTR (exp, 1) == '\0')
  4417.     {
  4418.       if (GET_MODE (exp) == VOIDmode)
  4419.         fatal ("Null MATCH_OPERAND specified as test");
  4420.       else
  4421.         printf ("GET_MODE (operands[%d]) == %smode",
  4422.             XINT (exp, 0), GET_MODE_NAME (GET_MODE (exp)));
  4423.     }
  4424.       else
  4425.     printf ("%s (operands[%d], %smode)",
  4426.         XSTR (exp, 1), XINT (exp, 0), GET_MODE_NAME (GET_MODE (exp)));
  4427.       break;
  4428.  
  4429.     /* Constant integer. */
  4430.     case CONST_INT:
  4431. #if HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_INT
  4432.       printf ("%d", XWINT (exp, 0));
  4433. #else
  4434.       printf ("%ld", XWINT (exp, 0));
  4435. #endif
  4436.       break;
  4437.  
  4438.     /* A random C expression. */
  4439.     case SYMBOL_REF:
  4440.       printf ("%s", XSTR (exp, 0));
  4441.       break;
  4442.  
  4443.     /* The address of the branch target.  */
  4444.     case MATCH_DUP:
  4445.       printf ("insn_addresses[INSN_UID (JUMP_LABEL (insn))]");
  4446.       break;
  4447.  
  4448.     /* The address of the current insn.  It would be more consistent with
  4449.        other usage to make this the address of the NEXT insn, but this gets
  4450.        too confusing because of the ambiguity regarding the length of the
  4451.        current insn.  */
  4452.     case PC:
  4453.       printf ("insn_current_address");
  4454.       break;
  4455.  
  4456.     default:
  4457.       fatal ("bad RTX code `%s' in attribute calculation\n",
  4458.          GET_RTX_NAME (code));
  4459.     }
  4460.  
  4461.   printf (")");
  4462. }
  4463.  
  4464. /* Given an attribute value, return the maximum CONST_STRING argument
  4465.    encountered.  It is assumed that they are all numeric.  */
  4466.  
  4467. static int
  4468. max_attr_value (exp)
  4469.      rtx exp;
  4470. {
  4471.   int current_max = 0;
  4472.   int n;
  4473.   int i;
  4474.  
  4475.   if (GET_CODE (exp) == CONST_STRING)
  4476.     return atoi (XSTR (exp, 0));
  4477.  
  4478.   else if (GET_CODE (exp) == COND)
  4479.     {
  4480.       for (i = 0; i < XVECLEN (exp, 0); i += 2)
  4481.     {
  4482.       n = max_attr_value (XVECEXP (exp, 0, i + 1));
  4483.       if (n > current_max)
  4484.         current_max = n;
  4485.     }
  4486.  
  4487.       n = max_attr_value (XEXP (exp, 1));
  4488.       if (n > current_max)
  4489.     current_max = n;
  4490.     }
  4491.  
  4492.   else if (GET_CODE (exp) == IF_THEN_ELSE)
  4493.     {
  4494.       current_max = max_attr_value (XEXP (exp, 1));
  4495.       n = max_attr_value (XEXP (exp, 2));
  4496.       if (n > current_max)
  4497.     current_max = n;
  4498.     }
  4499.  
  4500.   else
  4501.     abort ();
  4502.  
  4503.   return current_max;
  4504. }
  4505.  
  4506. /* Scan an attribute value, possibly a conditional, and record what actions
  4507.    will be required to do any conditional tests in it.
  4508.  
  4509.    Specifically, set
  4510.     `must_extract'      if we need to extract the insn operands
  4511.     `must_constrain'  if we must compute `which_alternative'
  4512.     `address_used'      if an address expression was used
  4513.     `length_used'      if an (eq_attr "length" ...) was used
  4514.  */
  4515.  
  4516. static void
  4517. walk_attr_value (exp)
  4518.      rtx exp;
  4519. {
  4520.   register int i, j;
  4521.   register char *fmt;
  4522.   RTX_CODE code;
  4523.  
  4524.   if (exp == NULL)
  4525.     return;
  4526.  
  4527.   code = GET_CODE (exp);
  4528.   switch (code)
  4529.     {
  4530.     case SYMBOL_REF:
  4531.       if (! RTX_UNCHANGING_P (exp))
  4532.     /* Since this is an arbitrary expression, it can look at anything.
  4533.        However, constant expressions do not depend on any particular
  4534.        insn.  */
  4535.     must_extract = must_constrain = 1;
  4536.       return;
  4537.  
  4538.     case MATCH_OPERAND:
  4539.       must_extract = 1;
  4540.       return;
  4541.  
  4542.     case EQ_ATTR:
  4543.       if (XSTR (exp, 0) == alternative_name)
  4544.     must_extract = must_constrain = 1;
  4545.       else if (strcmp (XSTR (exp, 0), "length") == 0)
  4546.     length_used = 1;
  4547.       return;
  4548.  
  4549.     case MATCH_DUP:
  4550.     case PC:
  4551.       address_used = 1;
  4552.       return;
  4553.     }
  4554.  
  4555.   for (i = 0, fmt = GET_RTX_FORMAT (code); i < GET_RTX_LENGTH (code); i++)
  4556.     switch (*fmt++)
  4557.       {
  4558.       case 'e':
  4559.       case 'u':
  4560.     walk_attr_value (XEXP (exp, i));
  4561.     break;
  4562.  
  4563.       case 'E':
  4564.     if (XVEC (exp, i) != NULL)
  4565.       for (j = 0; j < XVECLEN (exp, i); j++)
  4566.         walk_attr_value (XVECEXP (exp, i, j));
  4567.     break;
  4568.       }
  4569. }
  4570.  
  4571. /* Write out a function to obtain the attribute for a given INSN.  */
  4572.  
  4573. static void
  4574. write_attr_get (attr)
  4575.      struct attr_desc *attr;
  4576. {
  4577.   struct attr_value *av, *common_av;
  4578.  
  4579.   /* Find the most used attribute value.  Handle that as the `default' of the
  4580.      switch we will generate. */
  4581.   common_av = find_most_used (attr);
  4582.  
  4583.   /* Write out start of function, then all values with explicit `case' lines,
  4584.      then a `default', then the value with the most uses.  */
  4585.   if (!attr->is_numeric)
  4586.     printf ("enum attr_%s\n", attr->name);
  4587.   else if (attr->unsigned_p)
  4588.     printf ("unsigned int\n");
  4589.   else
  4590.     printf ("int\n");
  4591.  
  4592.   /* If the attribute name starts with a star, the remainder is the name of
  4593.      the subroutine to use, instead of `get_attr_...'.  */
  4594.   if (attr->name[0] == '*')
  4595.     printf ("%s (insn)\n", &attr->name[1]);
  4596.   else if (attr->is_const == 0)
  4597.     printf ("get_attr_%s (insn)\n", attr->name);
  4598.   else
  4599.     {
  4600.       printf ("get_attr_%s ()\n", attr->name);
  4601.       printf ("{\n");
  4602.  
  4603.       for (av = attr->first_value; av; av = av->next)
  4604.     if (av->num_insns != 0)
  4605.       write_attr_set (attr, 2, av->value, "return", ";",
  4606.               true_rtx, av->first_insn->insn_code,
  4607.               av->first_insn->insn_index);
  4608.  
  4609.       printf ("}\n\n");
  4610.       return;
  4611.     }
  4612.   printf ("     rtx insn;\n");
  4613.   printf ("{\n");
  4614.   printf ("  switch (recog_memoized (insn))\n");
  4615.   printf ("    {\n");
  4616.  
  4617.   for (av = attr->first_value; av; av = av->next)
  4618.     if (av != common_av)
  4619.       write_attr_case (attr, av, 1, "return", ";", 4, true_rtx);
  4620.  
  4621.   write_attr_case (attr, common_av, 0, "return", ";", 4, true_rtx);
  4622.   printf ("    }\n}\n\n");
  4623. }
  4624.  
  4625. /* Given an AND tree of known true terms (because we are inside an `if' with
  4626.    that as the condition or are in an `else' clause) and an expression,
  4627.    replace any known true terms with TRUE.  Use `simplify_and_tree' to do
  4628.    the bulk of the work.  */
  4629.  
  4630. static rtx
  4631. eliminate_known_true (known_true, exp, insn_code, insn_index)
  4632.      rtx known_true;
  4633.      rtx exp;
  4634.      int insn_code, insn_index;
  4635. {
  4636.   rtx term;
  4637.  
  4638.   known_true = SIMPLIFY_TEST_EXP (known_true, insn_code, insn_index);
  4639.  
  4640.   if (GET_CODE (known_true) == AND)
  4641.     {
  4642.       exp = eliminate_known_true (XEXP (known_true, 0), exp,
  4643.                   insn_code, insn_index);
  4644.       exp = eliminate_known_true (XEXP (known_true, 1), exp,
  4645.                   insn_code, insn_index);
  4646.     }
  4647.   else
  4648.     {
  4649.       term = known_true;
  4650.       exp = simplify_and_tree (exp, &term, insn_code, insn_index);
  4651.     }
  4652.  
  4653.   return exp;
  4654. }
  4655.  
  4656. /* Write out a series of tests and assignment statements to perform tests and
  4657.    sets of an attribute value.  We are passed an indentation amount and prefix
  4658.    and suffix strings to write around each attribute value (e.g., "return"
  4659.    and ";").  */
  4660.  
  4661. static void
  4662. write_attr_set (attr, indent, value, prefix, suffix, known_true,
  4663.         insn_code, insn_index)
  4664.      struct attr_desc *attr;
  4665.      int indent;
  4666.      rtx value;
  4667.      char *prefix;
  4668.      char *suffix;
  4669.      rtx known_true;
  4670.      int insn_code, insn_index;
  4671. {
  4672.   if (GET_CODE (value) == CONST_STRING)
  4673.     {
  4674.       write_indent (indent);
  4675.       printf ("%s ", prefix);
  4676.       write_attr_value (attr, value);
  4677.       printf ("%s\n", suffix);
  4678.     }
  4679.   else if (GET_CODE (value) == COND)
  4680.     {
  4681.       /* Assume the default value will be the default of the COND unless we
  4682.      find an always true expression.  */
  4683.       rtx default_val = XEXP (value, 1);
  4684.       rtx our_known_true = known_true;
  4685.       rtx newexp;
  4686.       int first_if = 1;
  4687.       int i;
  4688.  
  4689.       for (i = 0; i < XVECLEN (value, 0); i += 2)
  4690.     {
  4691.       rtx testexp;
  4692.       rtx inner_true;
  4693.  
  4694.       testexp = eliminate_known_true (our_known_true,
  4695.                       XVECEXP (value, 0, i),
  4696.                       insn_code, insn_index);
  4697.       newexp = attr_rtx (NOT, testexp);
  4698.       newexp  = insert_right_side (AND, our_known_true, newexp,
  4699.                        insn_code, insn_index);
  4700.  
  4701.       /* If the test expression is always true or if the next `known_true'
  4702.          expression is always false, this is the last case, so break
  4703.          out and let this value be the `else' case.  */
  4704.       if (testexp == true_rtx || newexp == false_rtx)
  4705.         {
  4706.           default_val = XVECEXP (value, 0, i + 1);
  4707.           break;
  4708.         }
  4709.  
  4710.       /* Compute the expression to pass to our recursive call as being
  4711.          known true.  */
  4712.       inner_true = insert_right_side (AND, our_known_true,
  4713.                       testexp, insn_code, insn_index);
  4714.  
  4715.       /* If this is always false, skip it.  */
  4716.       if (inner_true == false_rtx)
  4717.         continue;
  4718.  
  4719.       write_indent (indent);
  4720.       printf ("%sif ", first_if ? "" : "else ");
  4721.       first_if = 0;
  4722.       write_test_expr (testexp, 0);
  4723.       printf ("\n");
  4724.       write_indent (indent + 2);
  4725.       printf ("{\n");
  4726.  
  4727.       write_attr_set (attr, indent + 4,  
  4728.               XVECEXP (value, 0, i + 1), prefix, suffix,
  4729.               inner_true, insn_code, insn_index);
  4730.       write_indent (indent + 2);
  4731.       printf ("}\n");
  4732.       our_known_true = newexp;
  4733.     }
  4734.  
  4735.       if (! first_if)
  4736.     {
  4737.       write_indent (indent);
  4738.       printf ("else\n");
  4739.       write_indent (indent + 2);
  4740.       printf ("{\n");
  4741.     }
  4742.  
  4743.       write_attr_set (attr, first_if ? indent : indent + 4, default_val,
  4744.               prefix, suffix, our_known_true, insn_code, insn_index);
  4745.  
  4746.       if (! first_if)
  4747.     {
  4748.       write_indent (indent + 2);
  4749.       printf ("}\n");
  4750.     }
  4751.     }
  4752.   else
  4753.     abort ();
  4754. }
  4755.  
  4756. /* Write out the computation for one attribute value.  */
  4757.  
  4758. static void
  4759. write_attr_case (attr, av, write_case_lines, prefix, suffix, indent, known_true)
  4760.      struct attr_desc *attr;
  4761.      struct attr_value *av;
  4762.      int write_case_lines;
  4763.      char *prefix, *suffix;
  4764.      int indent;
  4765.      rtx known_true;
  4766. {
  4767.   struct insn_ent *ie;
  4768.  
  4769.   if (av->num_insns == 0)
  4770.     return;
  4771.  
  4772.   if (av->has_asm_insn)
  4773.     {
  4774.       write_indent (indent);
  4775.       printf ("case -1:\n");
  4776.       write_indent (indent + 2);
  4777.       printf ("if (GET_CODE (PATTERN (insn)) != ASM_INPUT\n");
  4778.       write_indent (indent + 2);
  4779.       printf ("    && asm_noperands (PATTERN (insn)) < 0)\n");
  4780.       write_indent (indent + 2);
  4781.       printf ("  fatal_insn_not_found (insn);\n");
  4782.     }
  4783.  
  4784.   if (write_case_lines)
  4785.     {
  4786.       for (ie = av->first_insn; ie; ie = ie->next)
  4787.     if (ie->insn_code != -1)
  4788.       {
  4789.         write_indent (indent);
  4790.         printf ("case %d:\n", ie->insn_code);
  4791.       }
  4792.     }
  4793.   else
  4794.     {
  4795.       write_indent (indent);
  4796.       printf ("default:\n");
  4797.     }
  4798.  
  4799.   /* See what we have to do to output this value.  */
  4800.   must_extract = must_constrain = address_used = 0;
  4801.   walk_attr_value (av->value);
  4802.  
  4803.   if (must_extract)
  4804.     {
  4805.       write_indent (indent + 2);
  4806.       printf ("insn_extract (insn);\n");
  4807.     }
  4808.  
  4809.   if (must_constrain)
  4810.     {
  4811. #ifdef REGISTER_CONSTRAINTS
  4812.       write_indent (indent + 2);
  4813.       printf ("if (! constrain_operands (INSN_CODE (insn), reload_completed))\n");
  4814.       write_indent (indent + 2);
  4815.       printf ("  fatal_insn_not_found (insn);\n");
  4816. #endif
  4817.     }
  4818.  
  4819.   write_attr_set (attr, indent + 2, av->value, prefix, suffix,
  4820.           known_true, av->first_insn->insn_code,
  4821.           av->first_insn->insn_index);
  4822.  
  4823.   if (strncmp (prefix, "return", 6))
  4824.     {
  4825.       write_indent (indent + 2);
  4826.       printf ("break;\n");
  4827.     }
  4828.   printf ("\n");
  4829. }
  4830.  
  4831. /* Utilities to write names in various forms.  */
  4832.  
  4833. static void
  4834. write_attr_valueq (attr, s)
  4835.      struct attr_desc *attr;
  4836.      char *s;
  4837. {
  4838.   if (attr->is_numeric)
  4839.     {
  4840.       printf ("%s", s);
  4841.       /* Make the blockage range values easier to read.  */
  4842.       if (strlen (s) > 1)
  4843.     printf (" /* 0x%x */", atoi (s));
  4844.     }
  4845.   else
  4846.     {
  4847.       write_upcase (attr->name);
  4848.       printf ("_");
  4849.       write_upcase (s);
  4850.     }
  4851. }
  4852.  
  4853. static void
  4854. write_attr_value (attr, value)
  4855.      struct attr_desc *attr;
  4856.      rtx value;
  4857. {
  4858.   if (GET_CODE (value) != CONST_STRING)
  4859.     abort ();
  4860.  
  4861.   write_attr_valueq (attr, XSTR (value, 0));
  4862. }
  4863.  
  4864. static void
  4865. write_upcase (str)
  4866.      char *str;
  4867. {
  4868.   while (*str)
  4869.     if (*str < 'a' || *str > 'z')
  4870.       printf ("%c", *str++);
  4871.     else
  4872.       printf ("%c", *str++ - 'a' + 'A');
  4873. }
  4874.  
  4875. static void
  4876. write_indent (indent)
  4877.      int indent;
  4878. {
  4879.   for (; indent > 8; indent -= 8)
  4880.     printf ("\t");
  4881.  
  4882.   for (; indent; indent--)
  4883.     printf (" ");
  4884. }
  4885.  
  4886. /* Write a subroutine that is given an insn that requires a delay slot, a
  4887.    delay slot ordinal, and a candidate insn.  It returns non-zero if the
  4888.    candidate can be placed in the specified delay slot of the insn.
  4889.  
  4890.    We can write as many as three subroutines.  `eligible_for_delay'
  4891.    handles normal delay slots, `eligible_for_annul_true' indicates that
  4892.    the specified insn can be annulled if the branch is true, and likewise
  4893.    for `eligible_for_annul_false'.
  4894.  
  4895.    KIND is a string distinguishing these three cases ("delay", "annul_true",
  4896.    or "annul_false").  */
  4897.  
  4898. static void
  4899. write_eligible_delay (kind)
  4900.      char *kind;
  4901. {
  4902.   struct delay_desc *delay;
  4903.   int max_slots;
  4904.   char str[50];
  4905.   struct attr_desc *attr;
  4906.   struct attr_value *av, *common_av;
  4907.   int i;
  4908.  
  4909.   /* Compute the maximum number of delay slots required.  We use the delay
  4910.      ordinal times this number plus one, plus the slot number as an index into
  4911.      the appropriate predicate to test.  */
  4912.  
  4913.   for (delay = delays, max_slots = 0; delay; delay = delay->next)
  4914.     if (XVECLEN (delay->def, 1) / 3 > max_slots)
  4915.       max_slots = XVECLEN (delay->def, 1) / 3;
  4916.  
  4917.   /* Write function prelude.  */
  4918.  
  4919.   printf ("int\n");
  4920.   printf ("eligible_for_%s (delay_insn, slot, candidate_insn)\n", kind);
  4921.   printf ("     rtx delay_insn;\n");
  4922.   printf ("     int slot;\n");
  4923.   printf ("     rtx candidate_insn;\n");
  4924.   printf ("{\n");
  4925.   printf ("  rtx insn;\n");
  4926.   printf ("\n");
  4927.   printf ("  if (slot >= %d)\n", max_slots);
  4928.   printf ("    abort ();\n");
  4929.   printf ("\n");
  4930.  
  4931.   /* If more than one delay type, find out which type the delay insn is.  */
  4932.  
  4933.   if (num_delays > 1)
  4934.     {
  4935.       attr = find_attr ("*delay_type", 0);
  4936.       if (! attr) abort ();
  4937.       common_av = find_most_used (attr);
  4938.  
  4939.       printf ("  insn = delay_insn;\n");
  4940.       printf ("  switch (recog_memoized (insn))\n");
  4941.       printf ("    {\n");
  4942.  
  4943.       sprintf (str, " * %d;\n      break;", max_slots);
  4944.       for (av = attr->first_value; av; av = av->next)
  4945.     if (av != common_av)
  4946.       write_attr_case (attr, av, 1, "slot +=", str, 4, true_rtx);
  4947.  
  4948.       write_attr_case (attr, common_av, 0, "slot +=", str, 4, true_rtx);
  4949.       printf ("    }\n\n");
  4950.  
  4951.       /* Ensure matched.  Otherwise, shouldn't have been called.  */
  4952.       printf ("  if (slot < %d)\n", max_slots);
  4953.       printf ("    abort ();\n\n");
  4954.     }
  4955.  
  4956.   /* If just one type of delay slot, write simple switch.  */
  4957.   if (num_delays == 1 && max_slots == 1)
  4958.     {
  4959.       printf ("  insn = candidate_insn;\n");
  4960.       printf ("  switch (recog_memoized (insn))\n");
  4961.       printf ("    {\n");
  4962.  
  4963.       attr = find_attr ("*delay_1_0", 0);
  4964.       if (! attr) abort ();
  4965.       common_av = find_most_used (attr);
  4966.  
  4967.       for (av = attr->first_value; av; av = av->next)
  4968.     if (av != common_av)
  4969.       write_attr_case (attr, av, 1, "return", ";", 4, true_rtx);
  4970.  
  4971.       write_attr_case (attr, common_av, 0, "return", ";", 4, true_rtx);
  4972.       printf ("    }\n");
  4973.     }
  4974.  
  4975.   else
  4976.     {
  4977.       /* Write a nested CASE.  The first indicates which condition we need to
  4978.      test, and the inner CASE tests the condition.  */
  4979.       printf ("  insn = candidate_insn;\n");
  4980.       printf ("  switch (slot)\n");
  4981.       printf ("    {\n");
  4982.  
  4983.       for (delay = delays; delay; delay = delay->next)
  4984.     for (i = 0; i < XVECLEN (delay->def, 1); i += 3)
  4985.       {
  4986.         printf ("    case %d:\n",
  4987.             (i / 3) + (num_delays == 1 ? 0 : delay->num * max_slots));
  4988.         printf ("      switch (recog_memoized (insn))\n");
  4989.         printf ("\t{\n");
  4990.  
  4991.         sprintf (str, "*%s_%d_%d", kind, delay->num, i / 3);
  4992.         attr = find_attr (str, 0);
  4993.         if (! attr) abort ();
  4994.         common_av = find_most_used (attr);
  4995.  
  4996.         for (av = attr->first_value; av; av = av->next)
  4997.           if (av != common_av)
  4998.         write_attr_case (attr, av, 1, "return", ";", 8, true_rtx);
  4999.  
  5000.         write_attr_case (attr, common_av, 0, "return", ";", 8, true_rtx);
  5001.         printf ("      }\n");
  5002.       }
  5003.  
  5004.       printf ("    default:\n");
  5005.       printf ("      abort ();\n");     
  5006.       printf ("    }\n");
  5007.     }
  5008.  
  5009.   printf ("}\n\n");
  5010. }
  5011.  
  5012. /* Write routines to compute conflict cost for function units.  Then write a
  5013.    table describing the available function units.  */
  5014.  
  5015. static void
  5016. write_function_unit_info ()
  5017. {
  5018.   struct function_unit *unit;
  5019.   int i;
  5020.  
  5021.   /* Write out conflict routines for function units.  Don't bother writing
  5022.      one if there is only one issue delay value.  */
  5023.  
  5024.   for (unit = units; unit; unit = unit->next)
  5025.     {
  5026.       if (unit->needs_blockage_function)
  5027.     write_complex_function (unit, "blockage", "block");
  5028.  
  5029.       /* If the minimum and maximum conflict costs are the same, there
  5030.      is only one value, so we don't need a function.  */
  5031.       if (! unit->needs_conflict_function)
  5032.     {
  5033.       unit->default_cost = make_numeric_value (unit->issue_delay.max);
  5034.       continue;
  5035.     }
  5036.  
  5037.       /* The function first computes the case from the candidate insn.  */
  5038.       unit->default_cost = make_numeric_value (0);
  5039.       write_complex_function (unit, "conflict_cost", "cost");
  5040.     }
  5041.  
  5042.   /* Now that all functions have been written, write the table describing
  5043.      the function units.   The name is included for documentation purposes
  5044.      only.  */
  5045.  
  5046.   printf ("struct function_unit_desc function_units[] = {\n");
  5047.  
  5048.   /* Write out the descriptions in numeric order, but don't force that order
  5049.      on the list.  Doing so increases the runtime of genattrtab.c.  */
  5050.   for (i = 0; i < num_units; i++)
  5051.     {
  5052.       for (unit = units; unit; unit = unit->next)
  5053.     if (unit->num == i)
  5054.       break;
  5055.  
  5056.       printf ("  {\"%s\", %d, %d, %d, %s, %d, %s_unit_ready_cost, ",
  5057.           unit->name, 1 << unit->num, unit->multiplicity,
  5058.           unit->simultaneity, XSTR (unit->default_cost, 0),
  5059.           unit->issue_delay.max, unit->name);
  5060.  
  5061.       if (unit->needs_conflict_function)
  5062.     printf ("%s_unit_conflict_cost, ", unit->name);
  5063.       else
  5064.     printf ("0, ");
  5065.  
  5066.       printf ("%d, ", unit->max_blockage);
  5067.  
  5068.       if (unit->needs_range_function)
  5069.     printf ("%s_unit_blockage_range, ", unit->name);
  5070.       else
  5071.     printf ("0, ");
  5072.  
  5073.       if (unit->needs_blockage_function)
  5074.     printf ("%s_unit_blockage", unit->name);
  5075.       else
  5076.     printf ("0");
  5077.  
  5078.       printf ("}, \n");
  5079.     }
  5080.  
  5081.   printf ("};\n\n");
  5082. }
  5083.  
  5084. static void
  5085. write_complex_function (unit, name, connection)
  5086.      struct function_unit *unit;
  5087.      char *name, *connection;
  5088. {
  5089.   struct attr_desc *case_attr, *attr;
  5090.   struct attr_value *av, *common_av;
  5091.   rtx value;
  5092.   char *str;
  5093.   int using_case;
  5094.   int i;
  5095.  
  5096.   printf ("static int\n");
  5097.   printf ("%s_unit_%s (executing_insn, candidate_insn)\n",
  5098.       unit->name, name);
  5099.   printf ("     rtx executing_insn;\n");
  5100.   printf ("     rtx candidate_insn;\n");
  5101.   printf ("{\n");
  5102.   printf ("  rtx insn;\n");
  5103.   printf ("  int casenum;\n\n");
  5104.   printf ("  insn = candidate_insn;\n");
  5105.   printf ("  switch (recog_memoized (insn))\n");
  5106.   printf ("    {\n");
  5107.  
  5108.   /* Write the `switch' statement to get the case value.  */
  5109.   str = (char *) alloca (strlen (unit->name) + strlen (name) + strlen (connection) + 10);
  5110.   sprintf (str, "*%s_cases", unit->name);
  5111.   case_attr = find_attr (str, 0);
  5112.   if (! case_attr) abort ();
  5113.   common_av = find_most_used (case_attr);
  5114.  
  5115.   for (av = case_attr->first_value; av; av = av->next)
  5116.     if (av != common_av)
  5117.       write_attr_case (case_attr, av, 1,
  5118.                "casenum =", ";", 4, unit->condexp);
  5119.  
  5120.   write_attr_case (case_attr, common_av, 0,
  5121.            "casenum =", ";", 4, unit->condexp);
  5122.   printf ("    }\n\n");
  5123.  
  5124.   /* Now write an outer switch statement on each case.  Then write
  5125.      the tests on the executing function within each.  */
  5126.   printf ("  insn = executing_insn;\n");
  5127.   printf ("  switch (casenum)\n");
  5128.   printf ("    {\n");
  5129.  
  5130.   for (i = 0; i < unit->num_opclasses; i++)
  5131.     {
  5132.       /* Ensure using this case.  */
  5133.       using_case = 0;
  5134.       for (av = case_attr->first_value; av; av = av->next)
  5135.     if (av->num_insns
  5136.         && contained_in_p (make_numeric_value (i), av->value))
  5137.       using_case = 1;
  5138.  
  5139.       if (! using_case)
  5140.     continue;
  5141.  
  5142.       printf ("    case %d:\n", i);
  5143.       sprintf (str, "*%s_%s_%d", unit->name, connection, i);
  5144.       attr = find_attr (str, 0);
  5145.       if (! attr) abort ();
  5146.  
  5147.       /* If single value, just write it.  */
  5148.       value = find_single_value (attr);
  5149.       if (value)
  5150.     write_attr_set (attr, 6, value, "return", ";\n", true_rtx, -2);
  5151.       else
  5152.     {
  5153.       common_av = find_most_used (attr);
  5154.       printf ("      switch (recog_memoized (insn))\n");
  5155.       printf ("\t{\n");
  5156.  
  5157.       for (av = attr->first_value; av; av = av->next)
  5158.         if (av != common_av)
  5159.           write_attr_case (attr, av, 1,
  5160.                    "return", ";", 8, unit->condexp);
  5161.  
  5162.       write_attr_case (attr, common_av, 0,
  5163.                "return", ";", 8, unit->condexp);
  5164.       printf ("      }\n\n");
  5165.     }
  5166.     }
  5167.  
  5168.   printf ("    }\n}\n\n");
  5169. }
  5170.  
  5171. /* This page contains miscellaneous utility routines.  */
  5172.  
  5173. /* Given a string, return the number of comma-separated elements in it.
  5174.    Return 0 for the null string.  */
  5175.  
  5176. static int
  5177. n_comma_elts (s)
  5178.      char *s;
  5179. {
  5180.   int n;
  5181.  
  5182.   if (*s == '\0')
  5183.     return 0;
  5184.  
  5185.   for (n = 1; *s; s++)
  5186.     if (*s == ',')
  5187.       n++;
  5188.  
  5189.   return n;
  5190. }
  5191.  
  5192. /* Given a pointer to a (char *), return a malloc'ed string containing the
  5193.    next comma-separated element.  Advance the pointer to after the string
  5194.    scanned, or the end-of-string.  Return NULL if at end of string.  */
  5195.  
  5196. static char *
  5197. next_comma_elt (pstr)
  5198.      char **pstr;
  5199. {
  5200.   char *out_str;
  5201.   char *p;
  5202.  
  5203.   if (**pstr == '\0')
  5204.     return NULL;
  5205.  
  5206.   /* Find end of string to compute length.  */
  5207.   for (p = *pstr; *p != ',' && *p != '\0'; p++)
  5208.     ;
  5209.  
  5210.   out_str = attr_string (*pstr, p - *pstr);
  5211.   *pstr = p;
  5212.  
  5213.   if (**pstr == ',')
  5214.     (*pstr)++;
  5215.  
  5216.   return out_str;
  5217. }
  5218.  
  5219. #ifdef MPW
  5220. #pragma segment GENAT03
  5221. #endif
  5222.  
  5223. /* Return a `struct attr_desc' pointer for a given named attribute.  If CREATE
  5224.    is non-zero, build a new attribute, if one does not exist.  */
  5225.  
  5226. static struct attr_desc *
  5227. find_attr (name, create)
  5228.      char *name;
  5229.      int create;
  5230. {
  5231.   struct attr_desc *attr;
  5232.   int index;
  5233.  
  5234.   /* Before we resort to using `strcmp', see if the string address matches
  5235.      anywhere.  In most cases, it should have been canonicalized to do so.  */
  5236.   if (name == alternative_name)
  5237.     return NULL;
  5238.  
  5239.   index = name[0] & (MAX_ATTRS_INDEX - 1);
  5240.   for (attr = attrs[index]; attr; attr = attr->next)
  5241.     if (name == attr->name)
  5242.       return attr;
  5243.  
  5244.   /* Otherwise, do it the slow way.  */
  5245.   for (attr = attrs[index]; attr; attr = attr->next)
  5246.     if (name[0] == attr->name[0] && ! strcmp (name, attr->name))
  5247.       return attr;
  5248.  
  5249.   if (! create)
  5250.     return NULL;
  5251.  
  5252.   attr = (struct attr_desc *) oballoc (sizeof (struct attr_desc));
  5253.   attr->name = attr_string (name, strlen (name));
  5254.   attr->first_value = attr->default_val = NULL;
  5255.   attr->is_numeric = attr->negative_ok = attr->is_const = attr->is_special = 0;
  5256.   attr->next = attrs[index];
  5257.   attrs[index] = attr;
  5258.  
  5259.   return attr;
  5260. }
  5261.  
  5262. /* Create internal attribute with the given default value.  */
  5263.  
  5264. static void
  5265. make_internal_attr (name, value, special)
  5266.      char *name;
  5267.      rtx value;
  5268.      int special;
  5269. {
  5270.   struct attr_desc *attr;
  5271.  
  5272.   attr = find_attr (name, 1);
  5273.   if (attr->default_val)
  5274.     abort ();
  5275.  
  5276.   attr->is_numeric = 1;
  5277.   attr->is_const = 0;
  5278.   attr->is_special = (special & 1) != 0;
  5279.   attr->negative_ok = (special & 2) != 0;
  5280.   attr->unsigned_p = (special & 4) != 0;
  5281.   attr->default_val = get_attr_value (value, attr, -2);
  5282. }
  5283.  
  5284. /* Find the most used value of an attribute.  */
  5285.  
  5286. static struct attr_value *
  5287. find_most_used (attr)
  5288.      struct attr_desc *attr;
  5289. {
  5290.   struct attr_value *av;
  5291.   struct attr_value *most_used;
  5292.   int nuses;
  5293.  
  5294.   most_used = NULL;
  5295.   nuses = -1;
  5296.  
  5297.   for (av = attr->first_value; av; av = av->next)
  5298.     if (av->num_insns > nuses)
  5299.       nuses = av->num_insns, most_used = av;
  5300.  
  5301.   return most_used;
  5302. }
  5303.  
  5304. /* If an attribute only has a single value used, return it.  Otherwise
  5305.    return NULL.  */
  5306.  
  5307. static rtx
  5308. find_single_value (attr)
  5309.      struct attr_desc *attr;
  5310. {
  5311.   struct attr_value *av;
  5312.   rtx unique_value;
  5313.  
  5314.   unique_value = NULL;
  5315.   for (av = attr->first_value; av; av = av->next)
  5316.     if (av->num_insns)
  5317.       {
  5318.     if (unique_value)
  5319.       return NULL;
  5320.     else
  5321.       unique_value = av->value;
  5322.       }
  5323.  
  5324.   return unique_value;
  5325. }
  5326.  
  5327. /* Return (attr_value "n") */
  5328.  
  5329. static rtx
  5330. make_numeric_value (n)
  5331.      int n;
  5332. {
  5333.   static rtx int_values[20];
  5334.   rtx exp;
  5335.   char *p;
  5336.  
  5337.   if (n < 0)
  5338.     abort ();
  5339.  
  5340.   if (n < 20 && int_values[n])
  5341.     return int_values[n];
  5342.  
  5343.   p = attr_printf (MAX_DIGITS, "%d", n);
  5344.   exp = attr_rtx (CONST_STRING, p);
  5345.  
  5346.   if (n < 20)
  5347.     int_values[n] = exp;
  5348.  
  5349.   return exp;
  5350. }
  5351.  
  5352. static void
  5353. extend_range (range, min, max)
  5354.      struct range *range;
  5355.      int min;
  5356.      int max;
  5357. {
  5358.   if (range->min > min) range->min = min;
  5359.   if (range->max < max) range->max = max;
  5360. }
  5361.  
  5362. char *
  5363. xrealloc (ptr, size)
  5364.      char *ptr;
  5365.      unsigned size;
  5366. {
  5367.   char *result = (char *) realloc (ptr, size);
  5368.   if (!result)
  5369.     fatal ("virtual memory exhausted");
  5370.   return result;
  5371. }
  5372.  
  5373. char *
  5374. xmalloc (size)
  5375.      unsigned size;
  5376. {
  5377.   register char *val = (char *) malloc (size);
  5378.  
  5379.   if (val == 0)
  5380.     fatal ("virtual memory exhausted");
  5381.   return val;
  5382. }
  5383.  
  5384. static rtx
  5385. copy_rtx_unchanging (orig)
  5386.      register rtx orig;
  5387. {
  5388. #if 0
  5389.   register rtx copy;
  5390.   register RTX_CODE code;
  5391. #endif
  5392.  
  5393.   if (RTX_UNCHANGING_P (orig) || MEM_IN_STRUCT_P (orig))
  5394.     return orig;
  5395.  
  5396.   MEM_IN_STRUCT_P (orig) = 1;
  5397.   return orig;
  5398.  
  5399. #if 0
  5400.   code = GET_CODE (orig);
  5401.   switch (code)
  5402.     {
  5403.     case CONST_INT:
  5404.     case CONST_DOUBLE:
  5405.     case SYMBOL_REF:
  5406.     case CODE_LABEL:
  5407.       return orig;
  5408.     }
  5409.  
  5410.   copy = rtx_alloc (code);
  5411.   PUT_MODE (copy, GET_MODE (orig));
  5412.   RTX_UNCHANGING_P (copy) = 1;
  5413.   
  5414.   bcopy (&XEXP (orig, 0), &XEXP (copy, 0),
  5415.      GET_RTX_LENGTH (GET_CODE (copy)) * sizeof (rtx));
  5416.   return copy;
  5417. #endif
  5418. }
  5419.  
  5420. static void
  5421. fatal (s, a1, a2)
  5422.      char *s;
  5423. {
  5424.   fprintf (stderr, "genattrtab: ");
  5425.   fprintf (stderr, s, a1, a2);
  5426.   fprintf (stderr, "\n");
  5427.   exit (FATAL_EXIT_CODE);
  5428. }
  5429.  
  5430. /* More 'friendly' abort that prints the line and file.
  5431.    config.h can #define abort fancy_abort if you like that sort of thing.  */
  5432.  
  5433. void
  5434. fancy_abort ()
  5435. {
  5436.   fatal ("Internal gcc abort.");
  5437. }
  5438.  
  5439. /* Determine if an insn has a constant number of delay slots, i.e., the
  5440.    number of delay slots is not a function of the length of the insn.  */
  5441.  
  5442. void
  5443. write_const_num_delay_slots ()
  5444. {
  5445.   struct attr_desc *attr = find_attr ("*num_delay_slots", 0);
  5446.   struct attr_value *av;
  5447.   struct insn_ent *ie;
  5448.   int i;
  5449.  
  5450.   if (attr)
  5451.     {
  5452.       printf ("int\nconst_num_delay_slots (insn)\n");
  5453.       printf ("     rtx *insn;\n");
  5454.       printf ("{\n");
  5455.       printf ("  switch (recog_memoized (insn))\n");
  5456.       printf ("    {\n");
  5457.  
  5458.       for (av = attr->first_value; av; av = av->next)
  5459.     {
  5460.       length_used = 0;
  5461.       walk_attr_value (av->value);
  5462.       if (length_used)
  5463.         {
  5464.           for (ie = av->first_insn; ie; ie = ie->next)
  5465.           if (ie->insn_code != -1)
  5466.         printf ("    case %d:\n", ie->insn_code);
  5467.           printf ("      return 0;\n");
  5468.         }
  5469.     }
  5470.  
  5471.       printf ("    default:\n");
  5472.       printf ("      return 1;\n");
  5473.       printf ("    }\n}\n");
  5474.     }
  5475. }
  5476.  
  5477.  
  5478. int
  5479. main (argc, argv)
  5480.      int argc;
  5481.      char **argv;
  5482. {
  5483.   rtx desc;
  5484.   FILE *infile;
  5485.   register int c;
  5486.   struct attr_desc *attr;
  5487.   struct insn_def *id;
  5488.   rtx tem;
  5489.   int i;
  5490.  
  5491. #ifdef RLIMIT_STACK
  5492.   /* Get rid of any avoidable limit on stack size.  */
  5493.   {
  5494.     struct rlimit rlim;
  5495.  
  5496.     /* Set the stack limit huge so that alloca does not fail. */
  5497.     getrlimit (RLIMIT_STACK, &rlim);
  5498.     rlim.rlim_cur = rlim.rlim_max;
  5499.     setrlimit (RLIMIT_STACK, &rlim);
  5500.   }
  5501. #endif /* RLIMIT_STACK defined */
  5502.  
  5503.   obstack_init (rtl_obstack);
  5504.   obstack_init (hash_obstack);
  5505.   obstack_init (temp_obstack);
  5506.  
  5507.   if (argc <= 1)
  5508.     fatal ("No input file name.");
  5509.  
  5510.   infile = fopen (argv[1], "r");
  5511.   if (infile == 0)
  5512.     {
  5513.       perror (argv[1]);
  5514.       exit (FATAL_EXIT_CODE);
  5515.     }
  5516.  
  5517.   init_rtl ();
  5518.  
  5519.   /* Set up true and false rtx's */
  5520.   true_rtx = rtx_alloc (CONST_INT);
  5521.   XWINT (true_rtx, 0) = 1;
  5522.   false_rtx = rtx_alloc (CONST_INT);
  5523.   XWINT (false_rtx, 0) = 0;
  5524.   RTX_UNCHANGING_P (true_rtx) = RTX_UNCHANGING_P (false_rtx) = 1;
  5525.   RTX_INTEGRATED_P (true_rtx) = RTX_INTEGRATED_P (false_rtx) = 1;
  5526.  
  5527.   alternative_name = attr_string ("alternative", strlen ("alternative"));
  5528.  
  5529.   printf ("/* Generated automatically by the program `genattrtab'\n\
  5530. from the machine description file `md'.  */\n\n");
  5531.  
  5532.   /* Read the machine description.  */
  5533.  
  5534.   while (1)
  5535.     {
  5536.       c = read_skip_spaces (infile);
  5537.       if (c == EOF)
  5538.     break;
  5539.       ungetc (c, infile);
  5540.  
  5541.       desc = read_rtx (infile);
  5542.       if (GET_CODE (desc) == DEFINE_INSN
  5543.       || GET_CODE (desc) == DEFINE_PEEPHOLE
  5544.       || GET_CODE (desc) == DEFINE_ASM_ATTRIBUTES)
  5545.     gen_insn (desc);
  5546.  
  5547.       else if (GET_CODE (desc) == DEFINE_EXPAND)
  5548.     insn_code_number++, insn_index_number++;
  5549.  
  5550.       else if (GET_CODE (desc) == DEFINE_SPLIT)
  5551.     insn_code_number++, insn_index_number++;
  5552.  
  5553.       else if (GET_CODE (desc) == DEFINE_ATTR)
  5554.     {
  5555.       gen_attr (desc);
  5556.       insn_index_number++;
  5557.     }
  5558.  
  5559.       else if (GET_CODE (desc) == DEFINE_DELAY)
  5560.     {
  5561.       gen_delay (desc);
  5562.       insn_index_number++;
  5563.     }
  5564.  
  5565.       else if (GET_CODE (desc) == DEFINE_FUNCTION_UNIT)
  5566.     {
  5567.       gen_unit (desc);
  5568.       insn_index_number++;
  5569.     }
  5570.     }
  5571.  
  5572.   /* If we didn't have a DEFINE_ASM_ATTRIBUTES, make a null one.  */
  5573.   if (! got_define_asm_attributes)
  5574.     {
  5575.       tem = rtx_alloc (DEFINE_ASM_ATTRIBUTES);
  5576.       XVEC (tem, 0) = rtvec_alloc (0);
  5577.       gen_insn (tem);
  5578.     }
  5579.  
  5580.   /* Expand DEFINE_DELAY information into new attribute.  */
  5581.   if (num_delays)
  5582.     expand_delays ();
  5583.  
  5584.   /* Expand DEFINE_FUNCTION_UNIT information into new attributes.  */
  5585.   if (num_units)
  5586.     expand_units ();
  5587.  
  5588.   printf ("#include \"config.h\"\n");
  5589.   printf ("#include \"rtl.h\"\n");
  5590.   printf ("#include \"insn-config.h\"\n");
  5591.   printf ("#include \"recog.h\"\n");
  5592.   printf ("#include \"regs.h\"\n");
  5593.   printf ("#include \"real.h\"\n");
  5594.   printf ("#include \"output.h\"\n");
  5595.   printf ("#include \"insn-attr.h\"\n");
  5596.   printf ("\n");  
  5597.   printf ("#define operands recog_operand\n\n");
  5598.  
  5599.   /* Make `insn_alternatives'.  */
  5600.   insn_alternatives = (int *) oballoc (insn_code_number * sizeof (int));
  5601.   for (id = defs; id; id = id->next)
  5602.     if (id->insn_code >= 0)
  5603.       insn_alternatives[id->insn_code] = (1 << id->num_alternatives) - 1;
  5604.  
  5605.   /* Make `insn_n_alternatives'.  */
  5606.   insn_n_alternatives = (int *) oballoc (insn_code_number * sizeof (int));
  5607.   for (id = defs; id; id = id->next)
  5608.     if (id->insn_code >= 0)
  5609.       insn_n_alternatives[id->insn_code] = id->num_alternatives;
  5610.  
  5611.   /* Prepare to write out attribute subroutines by checking everything stored
  5612.      away and building the attribute cases.  */
  5613.  
  5614.   check_defs ();
  5615.   for (i = 0; i < MAX_ATTRS_INDEX; i++)
  5616.     for (attr = attrs[i]; attr; attr = attr->next)
  5617.       {
  5618.     attr->default_val->value
  5619.       = check_attr_value (attr->default_val->value, attr);
  5620.     fill_attr (attr);
  5621.       }
  5622.  
  5623.   /* Construct extra attributes for `length'.  */
  5624.   make_length_attrs ();
  5625.  
  5626.   /* Perform any possible optimizations to speed up compilation. */
  5627.   optimize_attrs ();
  5628.  
  5629.   /* Now write out all the `gen_attr_...' routines.  Do these before the
  5630.      special routines (specifically before write_function_unit_info), so
  5631.      that they get defined before they are used.  */
  5632.  
  5633.   for (i = 0; i < MAX_ATTRS_INDEX; i++)
  5634.     for (attr = attrs[i]; attr; attr = attr->next)
  5635.       {
  5636.     if (! attr->is_special)
  5637.       write_attr_get (attr);
  5638.       }
  5639.  
  5640.   /* Write out delay eligibility information, if DEFINE_DELAY present.
  5641.      (The function to compute the number of delay slots will be written
  5642.      below.)  */
  5643.   if (num_delays)
  5644.     {
  5645.       write_eligible_delay ("delay");
  5646.       if (have_annul_true)
  5647.     write_eligible_delay ("annul_true");
  5648.       if (have_annul_false)
  5649.     write_eligible_delay ("annul_false");
  5650.     }
  5651.  
  5652.   /* Write out information about function units.  */
  5653.   if (num_units)
  5654.     write_function_unit_info ();
  5655.  
  5656.   /* Write out constant delay slot info */
  5657.   write_const_num_delay_slots ();
  5658.  
  5659.   fflush (stdout);
  5660.   exit (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);
  5661.   /* NOTREACHED */
  5662.   return 0;
  5663. }
  5664.